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

Ability to set variables shared between stages

    XMLWordPrintable

    Details

    • Similar Issues:
    • Epic Link:
    • Sprint:
      Declarative backlog

      Description

      It would be extremely useful to be able to share variables between stages ; currently, environment variables are overriden per-stage only, given the following example : 

       

      stages {
          stage('Setup profile') {
              environment {
                  MVNARGS = "-P${params.profile}"
              }
              when {
                  expression {
                      params.profile != '' 
                  }
              }
              steps {
                  echo "deploying as args:${env.MVNARGS} - env:${MVNARGS} - pprofile:${params.profile} - ..."
              }
          }
          stage('Build') {
              steps {
                  sh "mvn ${env.MVNARGS} xxxxxxx"
              }
          }
      }
      

      In Build, MVNARGS is null because the override from the Setup profile is stage scoped.

      I did not find a workaround for this, I've tried to share using the params Map but it's an unmodifiable read-only map. 

      Any ideas ?

       

      Thanks

       

       

        Attachments

          Issue Links

            Activity

            laurentperez laurent perez created issue -
            jamesdumay James Dumay made changes -
            Field Original Value New Value
            Epic Link JENKINS-45422 [ 183590 ]
            abayer Andrew Bayer made changes -
            Link This issue is duplicated by JENKINS-43408 [ JENKINS-43408 ]
            abayer Andrew Bayer made changes -
            Sprint Declarative backlog [ 621 ]
            jtaboada Jose Blas Camacho Taboada made changes -
            Assignee Andrew Bayer [ abayer ] Jose Blas Camacho Taboada [ jtaboada ]
            jtaboada Jose Blas Camacho Taboada made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jtaboada Jose Blas Camacho Taboada made changes -
            Status In Progress [ 3 ] Open [ 1 ]
            jtaboada Jose Blas Camacho Taboada made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jtaboada Jose Blas Camacho Taboada made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            abayer Andrew Bayer made changes -
            Status In Review [ 10005 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] Open [ 1 ]
            jtaboada Jose Blas Camacho Taboada made changes -
            Assignee Jose Blas Camacho Taboada [ jtaboada ] Andrew Bayer [ abayer ]
            abayer Andrew Bayer made changes -
            Link This issue is duplicated by JENKINS-55771 [ JENKINS-55771 ]
            skechav Sakis Kechlimparis made changes -
            Rank Ranked higher
            skechav Sakis Kechlimparis made changes -
            Rank Ranked lower
            skechav Sakis Kechlimparis made changes -
            Rank Ranked higher
            skechav Sakis Kechlimparis made changes -
            Rank Ranked higher
            skechav Sakis Kechlimparis made changes -
            Rank Ranked lower
            skechav Sakis Kechlimparis made changes -
            Rank Ranked higher
            jglick Jesse Glick made changes -
            Description It would be extremely useful to be able to share variables between stages ; currently, environment variables are overriden per-stage only, given the following example : 

            {{stages \{}}
            {{ stage('Setup profile') \{}}
            {{ environment \{}}
            {{ MVNARGS = "-P$\{params.profile}"}}
            {{ }}}
            {{ when \{}}
            {{ expression \{}}
            {{ params.profile != '' }}
            {{ }}}
            {{ }}}
            {{ steps \{}}
            {{ echo "deploying as args:$\{env.MVNARGS} - env:$\{MVNARGS} - pprofile:$\{params.profile} - ..."}}
            {{ }}}
            {{ }}}
            {{ stage('Build') \{}}
            {{steps\{}}
            {{ sh "mvn $\{env.MVNARGS} xxxxxxx"}}
            {{ }}}}

             

            In Build, MVNARGS is null because the override from the Setup profile is stage scoped.

            I did not find a workaround for this, I've tried to share using the params Map but it's an unmodifiable read-only map. 

            Any ideas ?

             

            Thanks

             

             
            It would be extremely useful to be able to share variables between stages ; currently, environment variables are overriden per-stage only, given the following example : 

             {code}
            stages {
                stage('Setup profile') {
                    environment {
                        MVNARGS = "-P${params.profile}"
                    }
                    when {
                        expression {
                            params.profile != ''
                        }
                    }
                    steps {
                        echo "deploying as args:${env.MVNARGS} - env:${MVNARGS} - pprofile:${params.profile} - ..."
                    }
                }
                stage('Build') {
                    steps {
                        sh "mvn ${env.MVNARGS} xxxxxxx"
                    }
                }
            }
            {code}

            In Build, MVNARGS is null because the override from the Setup profile is stage scoped.

            I did not find a workaround for this, I've tried to share using the params Map but it's an unmodifiable read-only map. 

            Any ideas ?

             

            Thanks

             

             
            pandastic Alexandre Fabra Fernandez made changes -
            Rank Ranked lower
            abayer Andrew Bayer made changes -
            Assignee Andrew Bayer [ abayer ]

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              laurentperez laurent perez
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated: