jenkinsci / jenkinsci/workflow-durable-task-step-plugin
[JENKINS-45616] Multi-branch pipelines do not interpolate platform environment variables into Jenkins global environment variables
- Dominant language
- Java
- Stars
- 46
- Forks
- 110
- PR merge metrics
- No merged PRs in 30d
Description
Did not test this on any previous versions of Jenkins/Plugins
Steps:
- Install Maven and Gradle using SDKMAN (http://sdkman.io)
- Install NodeJS using NVM (https://github.com/creationix/nvm)
- Add a global environment variable PATH that appends the tool paths (${PATH}:${HOME}/.nvm/versions/node/v6.11.1/bin:${HOME}/.sdkman/candidates/maven/current/bin:...)
- Create a multi-branch (Jenkinsfile) build that executes a shell command using sh
Result:
[Pipeline] sh
[***JOB***-TGZIHGC5MANL6BRDMLV3HGPUPVWZW5TYQK3AXDKNEHCXHUAIDQNQ] Running shell script
nohup: failed to run command ‘sh’: No such file or directory
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
If I change the global environment variable to include /bin, /usr/bin etc. instead of using ${PATH} and dump out the value of ${PATH} during the build, I see the following:
[Pipeline] {
[Pipeline] sh
[***JOB***-TGZIHGC5MANL6BRDMLV3HGPUPVWZW5TYQK3AXDKNEHCXHUAIDQNQ] Running shell script
+ echo '${HOME}/.sdkman/candidates/maven/current/bin:${HOME}/.sdkman/candidates/gradle/current/bin:${HOME}/.nvm/versions/node/v6.11.1/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin'
${HOME}/.sdkman/candidates/maven/current/bin:${HOME}/.sdkman/candidates/gradle/current/bin:${HOME}/.nvm/versions/node/v6.11.1/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
This suggests that the platform environment variables are not being interpolated into the Jenkins global environment variables. Other Jenkins global environment variables do seem to be expanded however (such as if I set ${MAVEN_HOME} and use it in ${PATH}).
If I dump out ${PATH} from a non-pipeline Freestyle project shell step, I get the expected value (including both ${HOME} and ${PATH} expanded fully).
---
Originally reported by
gkrupa, imported from: Multi-branch pipelines do not interpolate platform environment variables into Jenkins global environment variables
Raw content of original issue
Did not test this on any previous versions of Jenkins/Plugins
Steps:
- Install Maven and Gradle using SDKMAN (http://sdkman.io)
- Install NodeJS using NVM (https://github.com/creationix/nvm)
- Add a global environment variable PATH that appends the tool paths (${PATH}:${HOME}/.nvm/versions/node/v6.11.1/bin:${HOME}/.sdkman/candidates/maven/current/bin:...)
- Create a multi-branch (Jenkinsfile) build that executes a shell command using sh
Result:
[Pipeline] sh
[***JOB***-TGZIHGC5MANL6BRDMLV3HGPUPVWZW5TYQK3AXDKNEHCXHUAIDQNQ] Running shell script
nohup: failed to run command ‘sh’: No such file or directory
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // nodeIf I change the global environment variable to include /bin, /usr/bin etc. instead of using ${PATH} and dump out the value of ${PATH} during the build, I see the following:
[Pipeline] {
[Pipeline] sh
[***JOB***-TGZIHGC5MANL6BRDMLV3HGPUPVWZW5TYQK3AXDKNEHCXHUAIDQNQ] Running shell script
+ echo '${HOME}/.sdkman/candidates/maven/current/bin:${HOME}/.sdkman/candidates/gradle/current/bin:${HOME}/.nvm/versions/node/v6.11.1/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin'
${HOME}/.sdkman/candidates/maven/current/bin:${HOME}/.sdkman/candidates/gradle/current/bin:${HOME}/.nvm/versions/node/v6.11.1/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbinThis suggests that the platform environment variables are not being interpolated into the Jenkins global environment variables. Other Jenkins global environment variables do seem to be expanded however (such as if I set ${MAVEN_HOME} and use it in ${PATH}).
If I dump out ${PATH} from a non-pipeline Freestyle project shell step, I get the expected value (including both ${HOME} and ${PATH} expanded fully).
environment
```
Jenkins 2.70 (run directly) accessed via nginx with self-signed TLS
Installed via RPM
No slave nodes
Pipeline: Multibranch 2.16
Pipeline 2.5
CentOS 7
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
Browser: Chrome 57
```
Contributor guide
Assessment
This issue has not been assessed yet.