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

Variable changes are shared between matrix (parallel) stages.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Blocker
    • Resolution: Unresolved
    • Component/s: pipeline
    • Labels:
    • Environment:
      Jenkins ver. 2.190.2
      Pipeline: API 2.83
      Pipeline: Basic Steps 2.19
      Pipeline: Declarative 1.5.0
    • Similar Issues:

      Description

      New matrix step provides ability to run the same code in parallel cells. But if that code assigns ANY variable (not just env), it gets overwritten later by the next cell. This is huge deal, it basically prevents from assigning any variable in this kind of pipeline which makes it nearly useless.

      The condition is to set variable, have a piece of code that takes some time to execute and use the already set variable after. This can be simulated with sleep().

      I boiled down my code to easily reproduce it, here is the pipeline:

      pipeline {
          parameters {
              booleanParam(name: 'RHEL5', defaultValue: true)
              booleanParam(name: 'RHEL6', defaultValue: true)
              booleanParam(name: 'RHEL7', defaultValue: true)
          }
          stages {
              stage('Matrix') {
                  matrix {
                      when {
                          anyOf {
                              expression { params.RHEL5 && env.RHEL == '5' }
                              expression { params.RHEL6 && env.RHEL == '6' }
                              expression { params.RHEL7 && env.RHEL == '7' }
                          }
                      }
                      axes {
                          axis {
                              name 'RHEL'
                              values '5', '6', '7'
                          }
                      }
                      stages {
                          stage('Build single'){
                              steps {
                                  script {
                                      echo "RHEL version: " + env.RHEL
                                      myVar = "something.something.RHEL-${env.RHEL}"
                                      echo "myVar: " + myVar
                                      sleep(10)
                                      echo "AFTER RHEL version: " + env.RHEL 
                                      echo "AFTER myVar: " + myVar
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
      

      The result of this code:

       

      RHEL version: 5
      myVar: something.something.RHEL-5
      Sleeping for 10 sec
      RHEL version: 6
      myVar: something.something.RHEL-6
      Sleeping for 10 sec
      RHEL version: 7
      myVar: something.something.RHEL-7
      Sleeping for 10 sec
      No need to sleep any longer
      RHEL version: 5
      myVar: something.something.RHEL-7
      No need to sleep any longer
      RHEL version: 6
      myVar: something.something.RHEL-7
      No need to sleep any longer
      RHEL version: 7
      myVar: something.something.RHEL-7

      As you can see, myVar gets overwritten by the last run cell even for the other cells.

       

       

        Attachments

          Activity

          kryslj Jakub Krysl created issue -
          kryslj Jakub Krysl made changes -
          Field Original Value New Value
          Description New matrix step provides ability to run the same code in parallel cells. But if that code assigns ANY variable (not just env), it gets overwritten later by the next cell. This is huge deal, it basically prevents from assigning any variable withing this kind of pipeline which makes it nearly useless.

          The condition is to set variable, have a piece of code that takes some time to execute and use the already set variable after. This can be simulated with sleep().

          I boiled down my code to easily reproduce it, here is the pipeline:
          {code:java}
          pipeline {
              parameters {
                  booleanParam(name: 'RHEL5', defaultValue: true)
                  booleanParam(name: 'RHEL6', defaultValue: true)
                  booleanParam(name: 'RHEL7', defaultValue: true)
              }
              stages {
                  stage('Matrix') {
                      matrix {
                          when {
                              anyOf {
                                  expression { params.RHEL5 && env.RHEL == '5' }
                                  expression { params.RHEL6 && env.RHEL == '6' }
                                  expression { params.RHEL7 && env.RHEL == '7' }
                              }
                          }
                          axes {
                              axis {
                                  name 'RHEL'
                                  values '5', '6', '7'
                              }
                          }
                          stages {
                              stage('Build single'){
                                  steps {
                                      script {
                                          echo "RHEL version: " + env.RHEL
                                          myVar = "something.something.RHEL-${env.RHEL}"
                                          echo "myVar: " + myVar
                                          sleep(10)
                                          echo "AFTER RHEL version: " + env.RHEL
                                          echo "AFTER myVar: " + myVar
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
          {code}
          The result of this code:

           
          {code:java}
          RHEL version: 5
          myVar: something.something.RHEL-5
          Sleeping for 10 sec
          RHEL version: 6
          myVar: something.something.RHEL-6
          Sleeping for 10 sec
          RHEL version: 7
          myVar: something.something.RHEL-7
          Sleeping for 10 sec
          No need to sleep any longer
          RHEL version: 5
          myVar: something.something.RHEL-7
          No need to sleep any longer
          RHEL version: 6
          myVar: something.something.RHEL-7
          No need to sleep any longer
          RHEL version: 7
          myVar: something.something.RHEL-7{code}
          As you can see, myVar gets overwritten by the last run cell even for the other cells.

           

           
          New matrix step provides ability to run the same code in parallel cells. But if that code assigns ANY variable (not just env), it gets overwritten later by the next cell. This is huge deal, it basically prevents from assigning any variable in this kind of pipeline which makes it nearly useless.

          The condition is to set variable, have a piece of code that takes some time to execute and use the already set variable after. This can be simulated with sleep().

          I boiled down my code to easily reproduce it, here is the pipeline:
          {code:java}
          pipeline {
              parameters {
                  booleanParam(name: 'RHEL5', defaultValue: true)
                  booleanParam(name: 'RHEL6', defaultValue: true)
                  booleanParam(name: 'RHEL7', defaultValue: true)
              }
              stages {
                  stage('Matrix') {
                      matrix {
                          when {
                              anyOf {
                                  expression { params.RHEL5 && env.RHEL == '5' }
                                  expression { params.RHEL6 && env.RHEL == '6' }
                                  expression { params.RHEL7 && env.RHEL == '7' }
                              }
                          }
                          axes {
                              axis {
                                  name 'RHEL'
                                  values '5', '6', '7'
                              }
                          }
                          stages {
                              stage('Build single'){
                                  steps {
                                      script {
                                          echo "RHEL version: " + env.RHEL
                                          myVar = "something.something.RHEL-${env.RHEL}"
                                          echo "myVar: " + myVar
                                          sleep(10)
                                          echo "AFTER RHEL version: " + env.RHEL
                                          echo "AFTER myVar: " + myVar
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
          {code}
          The result of this code:

           
          {code:java}
          RHEL version: 5
          myVar: something.something.RHEL-5
          Sleeping for 10 sec
          RHEL version: 6
          myVar: something.something.RHEL-6
          Sleeping for 10 sec
          RHEL version: 7
          myVar: something.something.RHEL-7
          Sleeping for 10 sec
          No need to sleep any longer
          RHEL version: 5
          myVar: something.something.RHEL-7
          No need to sleep any longer
          RHEL version: 6
          myVar: something.something.RHEL-7
          No need to sleep any longer
          RHEL version: 7
          myVar: something.something.RHEL-7{code}
          As you can see, myVar gets overwritten by the last run cell even for the other cells.

           

           
          kryslj Jakub Krysl made changes -
          Priority Major [ 3 ] Critical [ 2 ]
          kryslj Jakub Krysl made changes -
          Priority Critical [ 2 ] Blocker [ 1 ]
          prakashraj prakash raj made changes -
          Assignee prakash raj [ prakashraj ]
          prakashraj prakash raj made changes -
          Assignee prakash raj [ prakashraj ]

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            kryslj Jakub Krysl
            Votes:
            8 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated: