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

Global environment variables are not accessible outside of node { }

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • pipeline
    • None

      When configuring Global Environment Variables in the "Manage Jenkins" view, the environment variables only seem to be accessible via the env global variable if it is inside the context of a node step.

      I find this to be rather confusing, and would expect global variables defined in Jenkins to be visible in any scope within a Jenkinsfile.

      See attached screenshot and the console output below for a reproduction case

      node {
          sh 'printenv | grep -i foo'
          echo "env.FOO_PIPELINE is: ${env.FOO_PIPELINE}"
      }
      
      echo "Outside of a node: env.FOO_PIPELINE is: ${env.FOO_PIPELINE}"
      

      Results in:

      Started by user admin
      [Pipeline] node
      Running on master in /tmp/jenkins/workspace/printenv
      [Pipeline] {
      [Pipeline] sh
      [printenv] Running shell script
      + printenv
      + grep -i foo
      FOO_PIPELINE=beepboop
      [Pipeline] echo
      env.FOO_PIPELINE is: beepboop
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] echo
      Outside of a node: env.FOO_PIPELINE is: null
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

            cloudbees CloudBees Inc.
            rtyler R. Tyler Croy
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: