-
Bug
-
Resolution: Fixed
-
Minor
-
Jenkins ver. 2.32.1
Pipeline 2.5
EnvInject 1.2
After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:
environment
{ PATH="/a/new/bin:$PATH" }
The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:
pipeline
{ agent
environment {
PATH="/a/new/bin:${env.SCM_HOME}:$PATH"
SCM_HOME="${env.SCM_HOME}"
}
stages {
stage ('build') {
steps
}
}
}
OUTPUT:
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] echoPATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin
[Pipeline] echoSCM_HOME=/usr/local/bin/scmtools/
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of PipelineFinished: SUCCESS
Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
- depends on
-
JENKINS-42753 Generate runtime model directly from AST model
-
- Closed
-
[JENKINS-45916] Path is not getting set correctly in pipeline when there is a variable present
Description |
Original:
After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such: environment \{ PATH="/a/new/bin:$PATH" } The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example: pipeline \{ agent \{ label 'docker' } environment \{ PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH" SCM_HOME="$\{env.SCM_HOME}" } stages \{ stage ('build') \{ steps \{ echo "PATH=$PATH" echo "SCM_HOME=$SCM_HOME" } } } } OUTPUT: {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] withEnv{color}{color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] stage{color}{color:#9a9999}[Pipeline] \{ (build){color}{color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin{color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/{color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // stage{color}{color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // withEnv{color}{color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // node{color}{color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine. |
New:
After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such: environment \{ PATH="/a/new/bin:$PATH" } The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example: pipeline \{ agent \{ label 'docker' } environment \{ PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH" SCM_HOME="$\{env.SCM_HOME}" } stages \{ stage ('build') \{ steps \{ echo "PATH=$PATH" echo "SCM_HOME=$SCM_HOME" } } } } OUTPUT: {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] withEnv{color} {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] stage{color} {color:#9a9999}[Pipeline] \{ (build){color} {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/ {color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // stage{color} {color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // withEnv{color}{color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // node{color} {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine. |
Description |
Original:
After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such: environment \{ PATH="/a/new/bin:$PATH" } The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example: pipeline \{ agent \{ label 'docker' } environment \{ PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH" SCM_HOME="$\{env.SCM_HOME}" } stages \{ stage ('build') \{ steps \{ echo "PATH=$PATH" echo "SCM_HOME=$SCM_HOME" } } } } OUTPUT: {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] withEnv{color} {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] stage{color} {color:#9a9999}[Pipeline] \{ (build){color} {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/ {color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // stage{color} {color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // withEnv{color}{color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // node{color} {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine. |
New:
After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such: environment \{ PATH="/a/new/bin:$PATH" } The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example: pipeline \{ agent \{ label 'docker' } environment \{ PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH" SCM_HOME="$\{env.SCM_HOME}" } stages \{ stage ('build') \{ steps \{ echo "PATH=$PATH" echo "SCM_HOME=$SCM_HOME" } } } } OUTPUT: {color:#9a9999}[Pipeline] \{{color} {color:#9a9999}[Pipeline] withEnv{color} {color:#9a9999}[Pipeline] \{{color} {color:#9a9999}[Pipeline] stage{color} {color:#9a9999}[Pipeline] \{ (build){color} {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/ {color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // stage{color} {color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // withEnv{color} {color:#9a9999}[Pipeline] }{color} {color:#9a9999}[Pipeline] // node{color} {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine. |
Component/s | New: pipeline-model-definition-plugin [ 21706 ] | |
Component/s | Original: pipeline [ 21692 ] | |
Assignee | New: Andrew Bayer [ abayer ] | |
Labels | Original: environment-variables jenkins pipeline | New: declarative-variable-and-method-resolution environment-variables jenkins pipeline |
Status | Original: Open [ 1 ] | New: In Progress [ 3 ] |
Link |
New:
This issue depends on |
Resolution | New: Fixed [ 1 ] | |
Status | Original: In Progress [ 3 ] | New: Resolved [ 5 ] |
I think this'll be resolved as part of https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/174. I'll add relevant tests there tomorrow.