jenkinsci / jenkinsci/workflow-durable-task-step-plugin

[JENKINS-45616] Multi-branch pipelines do not interpolate platform environment variables into Jenkins global environment variables

Open
#535 5 comments 0 reactions 0 assignees View on GitHub
component:workflow-durable-task-step-plugin imported-jira-issue priority:minor resolution:unresolved
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:



  1. Install Maven and Gradle using SDKMAN (http://sdkman.io)

  2. Install NodeJS using NVM (https://github.com/creationix/nvm)

  3. 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:...)

  4. 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


  • status: Open
  • priority: Minor
  • component(s): workflow-durable-task-step-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 3
  • imported: 20251212-090250

Raw content of original issue

Did not test this on any previous versions of Jenkins/Plugins

Steps:



  1. Install Maven and Gradle using SDKMAN (http://sdkman.io)

  2. Install NodeJS using NVM (https://github.com/creationix/nvm)

  3. 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:...)

  4. 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).

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.