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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: pipeline
    • Labels:
      None
    • Environment:
    • Similar Issues:

      Description

      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.

        Attachments

          Activity

          Hide
          nan Arnie Alpenbeach added a comment - - edited

          If it's too difficult to implement the expected/desired behavior within the constraints of the existing syntax, perhaps consider adding support for post-node-allocation-evaluated expressions for customWorkspace using a closure, e.g.:

          customWorkspace {'slot' + env.EXECUTOR_NUMBER}
          
          Show
          nan Arnie Alpenbeach added a comment - - edited If it's too difficult to implement the expected/desired behavior within the constraints of the existing syntax, perhaps consider adding support for post-node-allocation-evaluated expressions for customWorkspace using a closure, e.g.: customWorkspace { 'slot' + env.EXECUTOR_NUMBER}

            People

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

              Dates

              Created:
              Updated: