3

I want to be able to pass a List variable to the Build command in Jenkinsfile something like:

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

When I try something like this I get an error:

hudson.model.PasswordParameterValue~PasswordParameterValue(name: String, value: String, description: String)}[], propagate?: boolean, quietPeriod?: int, wait?: boolean): java.lang.ClassCastException: class org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep.setParameters() expects java.util.List but received class java.lang.String

anuj0901
  • 573
  • 6
  • 8

2 Answers2

2

Was able to get through this by using below code:

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

You should pass Map to parameters:

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