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

Environment variables can't be used in agent configuration

      If you try something like

      agent {
        label "${SOME_ENV_VAR}"
      }
      environment {
        SOME_ENV_VAR = "some-label"
      }
      

      You'll get an error due to SOME_ENV_VAR not existing in the binding. Not ideal, obviously, but I'm not sure if we can actually solve this without significant rewrites.

          [JENKINS-43911] Environment variables can't be used in agent configuration

          Andrew Bayer created issue -
          Andrew Bayer made changes -
          Labels New: declarative-variable-and-method-resolution
          James Dumay made changes -
          Epic Link New: JENKINS-45422 [ 183590 ]

          Andrew Bayer added a comment -

          Core problem here is that we evaluate the environment after we enter the agent - there are plenty of valid use cases for using env vars that don't exist until we enter the agent (like WORKSPACE, e.g.) in the environment block, but less for using environment variables in the agent, IMO. So this probably won't happen.

          Andrew Bayer added a comment - Core problem here is that we evaluate the environment after we enter the agent - there are plenty of valid use cases for using env vars that don't exist until we enter the agent (like WORKSPACE , e.g.) in the environment block, but less for using environment variables in the agent, IMO. So this probably won't happen.

          I want to change the Mac address of the docker agent running my build without exposing it in the Jenkinsfile. Is there any other way to do this than using environment variables?

          Jasper Behrensdorf added a comment - I want to change the Mac address of the docker agent running my build without exposing it in the Jenkinsfile. Is there any other way to do this than using environment variables?

          Robby Pocase added a comment - - edited

          Other scenarios that won't work from my testing. I would expect both to work in 1.2, so this really may not even belong in this issue.

           

          def some_var = 'label'
          pipeline {
            agent { label "${some_var}" }
            ...
          }

           

          env.some_env_var = 'label'
          pipeline {
            agent { label "${env.some_env_var}" }
            ...
          }

           

          Robby Pocase added a comment - - edited Other scenarios that won't work from my testing. I would expect both to work in 1.2, so this really may not even belong in this issue.   def some_var = 'label' pipeline { agent { label "${some_var}" } ... }   env.some_env_var = 'label' pipeline { agent { label "${env.some_env_var}" } ... }  
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          Andrew Bayer added a comment -

          I've got a PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/189, buuuuut I'm not sure it's the right thing. We've got a cost-benefit analysis to do here - which matters more, already being on the agent when we evaluate/generate the environment and credentials, or having the environment and credentials available when we get onto the agent? I legitimately don't know yet and would like some discussion on this.

          Andrew Bayer added a comment - I've got a PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/189 , buuuuut I'm not sure it's the right thing. We've got a cost-benefit analysis to do here - which matters more, already being on the agent when we evaluate/generate the environment and credentials , or having the environment and credentials available when we get onto the agent? I legitimately don't know yet and would like some discussion on this.
          Andrew Bayer made changes -
          Remote Link New: This issue links to "PR #189 (Web Link)" [ 17613 ]
          Andrew Bayer made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]

            Unassigned Unassigned
            abayer Andrew Bayer
            Votes:
            22 Vote for this issue
            Watchers:
            32 Start watching this issue

              Created:
              Updated: