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

Declarative pipeline functions cannot access defined environment variables from environment block

    XMLWordPrintable

Details

    Description

      Functions that are called from within the environment block do not have access to environment variables that are defined previously in the same environment block. Parameters work as expected and accessing the function outside of the environment block works as expected.

      Example pipeline that exhibits the null environment variable function

      #!/usr/bin/env groovy
      
      def returnEnvVar() {
        env.VARIABLE
      }
      
      pipeline {
          environment {
            VARIABLE = "I'm set"
            COPY_VARIABLE = returnEnvVar() // this gets set to null
          }
          stages {
              stage('Print Environment') {
                  steps {
                      echo "${VARIABLE}"
                      echo "${COPY_VARIABLE}" // this prints out null
                  }
              }
          }
      }

      Attachments

        Activity

          brianskarda Brian Skarda created issue -
          abayer Andrew Bayer made changes -
          Field Original Value New Value
          Assignee Andrew Bayer [ abayer ]

          People

            Unassigned Unassigned
            brianskarda Brian Skarda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: