Jenkins管道:构建步骤的返回值

时间:2018-06-29 13:52:49

标签: jenkins groovy jenkins-pipeline

在Jenkins的此集成管道中,我使用the build step并行触发不同的构建,如下所示:

stage('trigger all builds')
{
  parallel
  {
    stage('componentA')
    {
      steps
      {
        script 
        {
          def myjob=build job: 'componentA', propagate: true, wait: true
        }
      }
    }
    stage('componentB')
    {
      steps 
      {
        script
        {
          def myjob=build job: 'componentB', propagate: true, wait: true
        }
      }
    }
  }
}

我想访问build步骤的返回值,以便可以在Groovy脚本中知道触发了什么作业名称,编号。

在示例中,我发现返回的对象具有getProjectName()getNumber()之类的吸气剂,可用于此目的。

但是我怎么知道返回对象的确切类以及可以调用的方法列表? Pipeline documentation中似乎缺少此内容。我特别要求这种情况,但总的来说,我怎么知道返回对象的类及其文档?

1 个答案:

答案 0 :(得分:18)

步骤文档是基于与插件捆绑在一起的一些文件生成的,有时这还不够。一种简单的方法是通过调用getClass仅打印出结果对象的class

def myjob=build job: 'componentB', propagate: true, wait: true
echo "${myjob.getClass()}"

此输出将告诉您结果(在这种情况下)是一个org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper,其中包含published Javadoc

对于其他情况,我通常必须深入研究Jenkins源代码。这是我的一般策略:

相关问题