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

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major
    • Component/s: pipeline
    • None
    • Environment:

      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.

            Assignee:
            Unassigned
            Reporter:
            Arnie Alpenbeach
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: