env hashmap randomly mixes values of two parallel nodes

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      Please, look at this simple pipeline script:

      def build(label) {
          // Set env globally (for all stages) on the current node
          env.MYENVVAR = env.WORKSPACE
      
          // Printout outside of stage
          print('WORKSPACE 0=' + env.WORKSPACE)
          print('MYENVVAR 0=' + env.MYENVVAR)
      
          stage ('Stage 1' + label) { // Printout in a stage
              print('WORKSPACE 1=' + env.WORKSPACE)
              print('MYENVVAR 1=' + env.MYENVVAR)
          }
      }
      
      // Main
      parallel(
          'Unix' : {
              node ('build-linux') {
                  build('Unix')
              }
          },
          'Windows' : {
              node ('build-win') {
                  build('Windows')
              }
          }
      )
      

      This results to this output:

      Running on build-linux in /home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
      Running on build-win in c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
      
      [Unix] WORKSPACE 0=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
      [Unix] MYENVVAR 0=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
      
      [Windows] WORKSPACE 0=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
      [Windows] MYENVVAR 0=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
      
      [Unix] WORKSPACE 1=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
      *[Unix] MYENVVAR 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up* // BUG !!
      
      [Windows] WORKSPACE 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
      [Windows] MYENVVAR 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
      

      So the bug is that the env.MYENVVAR inside the [Unix] parallel branch on Unix node somehow takes value of the [Windows] parallel branch.
      Expected result: env.MYENVVAR = env.WORKSPACE before all stages should have assigned env.MYENVVAR for all further stages, because it was done outside the stage, that is globally for the node.

      There is a workaround. If I change the pipeline script by adding withEnv{} this way it works:

      def build(label) {
      
          withEnv([ "MYENVVAR=" + env.WORKSPACE ]) { // WORKAROUND
          
              // Global
              //env.MYENVVAR = env.WORKSPACE
              print('WORKSPACE 0=' + env.WORKSPACE)
              print('MYENVVAR 0=' + env.MYENVVAR)
      
              stage ('Stage 1' + label) {
                  print('WORKSPACE 1=' + env.WORKSPACE)
                  print('MYENVVAR 1=' + env.MYENVVAR)
              }
          }
      }
      

      I don't know if my example is supposed to be supported, but if not then please fix it so that the null value is assigned. If the variable in one node {} takes value from another parallel node {} in a random way that seems to be really wrong.

            Assignee:
            Unassigned
            Reporter:
            Alexander Samoylov
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: