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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • blueocean-plugin, pipeline
    • Jenkins v2.138.1
      Java 1.8.0_131
      Blue Ocean v1.9.0
      Plugins: see plugins.txt

      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. 

        1. log.txt
          6 kB
          Nalin Makar
        2. plugins.txt
          5 kB
          Nalin Makar
        3. Screen Shot 2018-10-15 at 5.32.56 PM.png
          49 kB
          Nalin Makar

            nullin Nalin Makar
            nullin Nalin Makar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: