将运行参数传递给下游作业

时间:2019-12-23 09:49:44

标签: jenkins jenkins-plugins jenkins-groovy jenkins-job-dsl

假设我有一个运行参数如下的管道:

下游工作:

pipeline {
  parameters {
    run(name: 'NAME', filter: 'STABLE', projectName: 'myProject)
  }
}

现在,如何使用另一个作业中的该作业并传递运行参数?

主要工作:

pipeline {
  parameters {
    run(name: 'NAME', filter: 'STABLE', projectName: 'myProject)
  }
  stages {
    stage('stage 1') {
      steps {
         build(job: "downstreamJob",
           parameters: [
             run(name: 'NAME', value: NAME)])
      }
    }
  }
}

错误:

WARNING: Unknown parameter(s) found for class type 'hudson.model.RunParameterValue': value

Could not instantiate {job=downstreamJob, parameters=[@run(name=NAME,value=http://.....)]} for org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep: java.lang.IllegalArgumentException: Could not instantiate {name=NAME, value=http://.....} for hudson.model.RunParameterValue: java.lang.reflect.InvocationTargetException

1 个答案:

答案 0 :(得分:0)

解决方案是使用以下命令调用下游作业:

run(name: 'NAME', runId: NAME_JOBNAME + NAME_NUMBER)

它们是环境变量,runID的格式为:myProject#0