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

Declarative pipeline: env.EXECUTOR_NUMBER evaluates to null outside of steps{} block

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • pipeline
    • None

      Consider the following declarative Pipeline:

      pipeline {
        agent {
          node {
            label 'blunt'
            customWorkspace 'slot' + env.EXECUTOR_NUMBER
          }
        }
        stages {
          stage('Build') {
            steps {
              sh 'echo $WORKSPACE'
            }
          }
        }
      }
      

      The (curtailed) console output is:

      Running on blunt in /build/jenkins/workspace/pipeline-test
      Running in /build/jenkins/slotnull
      + echo /build/jenkins/slotnull
      

      What I would have expected instead (assuming 'blunt' is a single-executor node):

      Running on blunt in /build/jenkins/slot0
      + echo /build/jenkins/slot0
      

      One can somewhat work around this with ws steps, but with more complicated pipelines where multiple steps in multiple stages need to share the same custom workspace, that can get unwieldy.

      Other environment variables, like NODE_NAME, also evaluate to null in the same context.

            Unassigned Unassigned
            nan Arnie Alpenbeach
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: