-
Bug
-
Resolution: Unresolved
-
Minor
-
Jenkins 2.150.1, Pipeline-Groovy Plugin 2.57
I want to execute same job with same parameters five times
But the following code leads to only one actual execution:
pipeline { agent none stages { stage('Processing same project 5 times') { steps { script { def projectsBuilds = [:] for (int i = 0; i < 5; i++) { int currentIteration = i String uniqueRunName = String.format('Run #%d', currentIteration); def labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: 'Sample-Job']) print(String.format("This parameters set hash is \"%s\"", labelParameters.hashCode())) projectsBuilds[uniqueRunName] = { stage(String.format('Sample-Job execution #%d', currentIteration)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } }
As you see from execution log screen (screen0), though I explicitly instantiate "labelParameters" on each iteration, it has the same hash code in every iteration. Seems, Jenkins groovy plugin consider this situation as "one parameters container - one run"
Meanwhile if I just add one more parameter to container - current iteration index, groovy stops to "optimize" my code and now "labelParameters" has different hash code on every iteration. This leads to execution of "Sample-Job" 5 times, as intended (screen1)
pipeline { agent none stages { stage('Processing same project 5 times') { steps { script { def projectsBuilds = [:] for (int i = 0; i < 5; i++) { int currentIteration = i String uniqueRunName = String.format('Run #%d', currentIteration); def labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: 'Sample-Job']) labelParameters.add([$class: "StringParameterValue", name: "ITERATION_INDEX", value: currentIteration.toString()]) print(String.format("This parameters set hash is \"%s\"", labelParameters.hashCode())) projectsBuilds[uniqueRunName] = { stage(String.format('Sample-Job execution #%d', currentIteration)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } }
- depends on
-
JENKINS-55426 Using "for in" loop for generating tasks for "parallel" execution, causes all tasks to have last value from iterated collection
-
- Open
-
- is blocked by
-
JENKINS-55600 Parallel execution of same job N times with different parameters leads to only 1 execution of the job
-
- Closed
-
[JENKINS-55748] Jenkins cannot execute one job with the same (by value, not adress) parameters, more than once
Summary | Original: Jemnkins cannot execute more, than one job with the same (by value, not adress) parameters, more than once | New: Jenkins cannot execute more, than one job with the same (by value, not adress) parameters, more than once |
Link |
New:
This issue is blocked by |
Description |
Original:
I want to execute same job with same parameters five times But the following code leads to only one actual execution: {code:java} pipeline { agent none stages { stage('Processing same project 5 times') { steps { script { def projectsBuilds = [:] for (int i = 0; i < 5; i++) { int currentIteration = i String uniqueRunName = String.format('Run #%d', currentIteration); def labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: 'Sample-Job']) print(String.format("This parameters set hash is \"%s\"", labelParameters.hashCode())) projectsBuilds[uniqueRunName] = { stage(String.format('Sample-Job execution #%d', currentIteration)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } } {code} As you see from execution log screen (screen0), though I explicitly instantiate "labelParameters" on each iteration, it has the same hash code in every iteration. Seems, Jenkins groovy plugin consider this situation as "one parameters container - one run" Meanwhile if I just add one more parameter to container - current iteration index, groovy stops to "optimize" my code and now "labelParameters" has different hash code on every iteration. This leads to execution of "Sample-Job" 5 times, as intended (screen1) {code:java} pipeline { agent none stages { stage('Processing same project 5 times') { steps { script { def projectsBuilds = [:] for (int i = 0; i < 5; i++) { int currentIteration = i String uniqueRunName = String.format('Run #%d', currentIteration); def labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: 'Sample-Job']) labelParameters.add([$class: "StringParameterValue", name: "ITERATION_INDEX", value: currentIteration.toString()]) print(String.format("This parameters set hash is \"%s\"", labelParameters.hashCode())) projectsBuilds[uniqueRunName] = { stage(String.format('Sample-Job execution #%d', currentIteration)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } } {code} |
New:
I want to execute same job with same parameters five times But the following code leads to only one actual execution: {code:java} pipeline { agent none stages { stage('Processing same project 5 times') { steps { script { def projectsBuilds = [:] for (int i = 0; i < 5; i++) { int currentIteration = i String uniqueRunName = String.format('Run #%d', currentIteration); def labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: 'Sample-Job']) print(String.format("This parameters set hash is \"%s\"", labelParameters.hashCode())) projectsBuilds[uniqueRunName] = { stage(String.format('Sample-Job execution #%d', currentIteration)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } } {code} As you see from execution log screen (screen0), though I explicitly instantiate "labelParameters" on each iteration, it has the same hash code in every iteration. Seems, Jenkins groovy plugin consider this situation as "one parameters container - one run" Meanwhile if I just add one more parameter to container - current iteration index, groovy stops to "optimize" my code and now "labelParameters" has different hash code on every iteration. This leads to execution of "Sample-Job" 5 times, as intended (screen1) {code:java} pipeline { agent none stages { stage('Processing same project 5 times') { steps { script { def projectsBuilds = [:] for (int i = 0; i < 5; i++) { int currentIteration = i String uniqueRunName = String.format('Run #%d', currentIteration); def labelParameters = [] labelParameters.add([$class: 'LabelParameterValue', name: 'node', label: 'linux']) labelParameters.add([$class: "StringParameterValue", name: "PROJECT_NAME", value: 'Sample-Job']) labelParameters.add([$class: "StringParameterValue", name: "ITERATION_INDEX", value: currentIteration.toString()]) print(String.format("This parameters set hash is \"%s\"", labelParameters.hashCode())) projectsBuilds[uniqueRunName] = { stage(String.format('Sample-Job execution #%d', currentIteration)) { build job: 'Sample-Job', parameters: labelParameters } } } parallel projectsBuilds; } } } } } {code} |
Link | New: This issue depends on JENKINS-55426 [ JENKINS-55426 ] |
Summary | Original: Jenkins cannot execute more, than one job with the same (by value, not adress) parameters, more than once | New: Jenkins cannot execute one job with the same (by value, not adress) parameters, more than once |
Probably is a special case of this defect