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

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major
    • Component/s: pipeline
    • 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
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: