anuj0901
anuj0901

Reputation: 593

Pass a Groovy List as parameter to Build command in Jenkinsfile

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

Upvotes: 3

Views: 9877

Answers (2)

anuj0901
anuj0901

Reputation: 593

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
}

Upvotes: 2

Yuri Karpovich
Yuri Karpovich

Reputation: 402

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
}

Upvotes: 0

Related Questions