Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55748

Jenkins cannot execute one job with the same (by value, not adress) parameters, more than once

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

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

        Attachments

        1. screen0.jpg
          screen0.jpg
          156 kB
        2. screen1.jpg
          screen1.jpg
          171 kB

          Issue Links

            Activity

            alpanshin Alexandr Panshin created issue -
            alpanshin Alexandr Panshin made changes -
            Field Original Value New Value
            Summary Jemnkins cannot execute more, than one job with the same (by value, not adress) parameters, more than once Jenkins cannot execute more, than one job with the same (by value, not adress) parameters, more than once
            alpanshin Alexandr Panshin made changes -
            Link This issue is blocked by JENKINS-55600 [ JENKINS-55600 ]
            alpanshin Alexandr Panshin made changes -
            Description 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}

            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}

            alpanshin Alexandr Panshin made changes -
            Link This issue depends on JENKINS-55426 [ JENKINS-55426 ]
            alpanshin Alexandr Panshin made changes -
            Summary Jenkins cannot execute more, than one job with the same (by value, not adress) parameters, more than once Jenkins cannot execute one job with the same (by value, not adress) parameters, more than once

              People

              Assignee:
              vjuranek vjuranek
              Reporter:
              alpanshin Alexandr Panshin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: