- 
    
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
 
 -