patternMinor
Passing parameters of extendedChoice type to Jenkins Pipeline via jenkins-cli.jar
Viewed 0 times
jenkinspassingextendedchoicejartypeviacliparameterspipeline
Problem
I have the following declarative pipeline. It defines checkbox multi-choice parameter:
My goal is to call the pipeline via Jenkins CLI where passed values to
Running
Expected
The only way that worked is adding commas after
Is it the correct syntax to pass checkbox selections of
pipeline {
agent any
options {
ansiColor('xterm')
}
parameters {
extendedChoice description: '', multiSelectDelimiter: ',', name: 'NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value:'a,b,c', visibleItemCount: 3
}
stages {
stage('Run on all') {
steps {
script {
println params.NAMES
}
}
}
}
}My goal is to call the pipeline via Jenkins CLI where passed values to
NAMES parameter signifies selected checkboxes.Running
java -jar jenkins-cli.jar -s http://localhost:8080 -auth u:p -p NAMES='a' causes empty string to be printed by println params.NAMESExpected
a to be printed after calling the pipeline via Jenkins cli client.The only way that worked is adding commas after
a: java -jar jenkins-cli.jar -s http://localhost:8080 -auth u:p -p NAMES='a,,'Is it the correct syntax to pass checkbox selections of
extendedChoice type parameter?Solution
Try with tokenize (,) since the options were saved like a string.
Save 'NAMES' into a new variable, then tokenize with a comma "," since it was configured the parameters with multiSelectDelimiter: ','
Finally, you can iterate the array with a for-loop and use the elements as desire.
Save 'NAMES' into a new variable, then tokenize with a comma "," since it was configured the parameters with multiSelectDelimiter: ','
Finally, you can iterate the array with a for-loop and use the elements as desire.
def arr = userInput['NAMES'].tokenize(',')
arr.each { t ->
// t is the parameter option
sh("echo ${t}")
}
Context
StackExchange DevOps Q#11797, answer score: 1
Revisions (0)
No revisions yet.