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

Same user defined global step run in parallel stages gets passed incorrect variables

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Trying to create a Jenkins declarative pipeline that runs two stages in parallel, one for each project in a separate folder in the same repo. For each project, we run multiple stages, which are generated using a global variable 'buildProject'. We pass in folder1 and folder2 into the different invocations of buildProject, but due to possible race condition, the same folder is used to run almost all the stages, except for the first sequential stage in the first parallel stage.

      The pipeline is as follows:

      @Library('jenkins-pipeline-tools@master') _
      
      pipeline {
          agent {
             label 'build'
          }
          stages {
              stage('Build branch') {
                  when {
                      anyOf {
                          branch 'master'
                          changeRequest()
                      }
                  }
                  parallel {
                      stage('build 1') {
                          steps {
                              script {
                                  buildProject(folder: 'folder 1', type: 'py27', publish: false)
                              }
                          }
                      }
                      stage('build 2') {
                          steps {
                              script {
                                  buildProject(folder: 'folder 2', type: 'py36', publish: true)
                              }
                          }
                      }
                  }
              }
          }
      }

      And vars/buildProject.groovy is:

      def call(Map config) {
          folder = config.folder
          type = config.type
          publish = config.publish ?: false    stage("build-sar ${folder}") {
              echo "step Publish: ${PUBLISH_FROM_BRANCH}, Directory: ${folder}, type: ${type}"
          }    stage("coverage ${folder}") {
              echo "step Publish: ${PUBLISH_FROM_BRANCH}, Directory: ${folder}, type: ${type}"
          }    stage("build-wheel ${folder}") {
              echo "step Publish: ${PUBLISH_FROM_BRANCH}, Directory: ${folder}, type: ${type}"
          }
      } 

      Expected to see that folder1 is printed in echo statements and stage names for first stage of the parallel stages, where as folder2 is printed in the second of the parallel stages. 

      Actual behavior is that folder1 is printed only for the first sequential stage name of the first parallel stage. Rest all use and print folder2.

      See attached screen shot (Screen Shot 2018-10-15 at 5.32.56 PM.png) and log.txt for the actual execution results. 

        Attachments

          Activity

          Hide
          nullin Nalin Makar added a comment -

          looks like a user error on my end. I am trying to update my scripts.

          Show
          nullin Nalin Makar added a comment - looks like a user error on my end. I am trying to update my scripts.

            People

            Assignee:
            nullin Nalin Makar
            Reporter:
            nullin Nalin Makar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: