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

values set by environment directive are not captured for RunWrapper.getBuildVariables

    Details

    • Similar Issues:

      Description

      When using the environment directive in a declarative pipeline, the environment variables that are set are not captured and exposed via the RunWrapper.getBuildVariables method.

      For example, the following pipeline will yield an empty Map after execution.

      Jenkinsfile

      pipeline {
          environment {
              MY_ENVVAR = "example"
          }
      
          stages {
              stage("run job") {
                  steps {
                      sh 'printenv | sort'
                  }
              }
          }
      }

      Result

      [:]
      

        

      However, if we set this environment variable via the script directive it is captured and made available in the response of RunWrapper.getBuildVariables.

      Jenkinsfile

      pipeline {
         stages {
             stage("run job") {
                 steps {
                     script {
                         env.MY_ENVVAR = "example"
                     }
      
                     sh 'printenv | sort'
                 }
             }
         }
      }
      

      Result

      [MY_ENVVAR:example]

       

      I would expect that ALL custom set environment variables should be retrieved.

        Attachments

          Activity

          Hide
          savepointsam Sam Horton added a comment -

          Slightly related to JENKINS-36528.

          Show
          savepointsam Sam Horton added a comment - Slightly related to  JENKINS-36528 .

            People

            • Assignee:
              Unassigned
              Reporter:
              savepointsam Sam Horton
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: