-
Bug
-
Resolution: Duplicate
-
Minor
-
Jenkins 2.150.1, Pipeline-Groovy Plugin 2.57
1) I created sample job (see "sample_job_config.xml" attachment) which has "PROJECT_NAME" parameter
2) I want to run it in parallel 5 times with different "PROJECT_NAME" values. I created following script for this:
pipeline { agent none stages { stage('Processing projects') { steps { script { def projects = ['project0', 'project1', 'project2', 'project3', 'project4'] def projectsBuilds = [:] def labelParameters for (project in projects) { //JENKINS-55426 need to save iterated variable value into intermediate variable, otherwise there will be last value from collection for all jobs def currentProject = project labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: currentProject]) projectsBuilds[currentProject] = { stage(String.format('%s execution', currentProject)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } }
3) However, when I run this script it only invokes job ONCE, not FIVE TIMES (see screen)
- blocks
-
JENKINS-55748 Jenkins cannot execute one job with the same (by value, not adress) parameters, more than once
-
- Open
-
Though I still guess it is a defect (I suppose "labelParameters = []" instruction in Groovy should rewrite pointer value?), this problem seems to appear because of using same "labelParameters" variable for all of jobs.
Instantiating container for parameters for each job seems to solve the problem: