将Groovy列表作为参数传递给Jenkinsfile

时间:2019-08-29 19:34:05

标签: jenkins-pipeline groovydsl

我希望能够将List变量传递给Jenkinsfile中的Build命令,例如:

stage('test') {
  def listName = []
  build job: "/job/jobname", parameters: listName, propagate: false
}

当我尝试类似的操作时,我得到一个错误:

hudson.model.PasswordParameterValue〜PasswordParameterValue(名称:字符串,值:字符串,描述:字符串)} [],传播?:布尔值,quietPeriod ?:整数,等待?:布尔值):java.lang.ClassCastException:类org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep.setParameters()需要java.util.List但接收到类java.lang.String

2 个答案:

答案 0 :(得分:0)

您应将Map传递给parameters

stage('test') {
  def listName = [string(name: 'PARAM_NAME', value: "PARAM_VALUE")]
  build job: "/job/jobname", parameters: listName, propagate: false
}

答案 1 :(得分:0)

可以通过使用以下代码来解决此问题:

stage('test') {
   def listName = []
   listName .add([$class: 'StringParameterValue', name: "${listKey}", value: "${list.value}"])
   build job: "/job/jobname", parameters: listName, propagate: false
}