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

Multi-branch pipelines do not interpolate platform environment variables into Jenkins global environment variables

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
    • Similar Issues:

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

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Can you share your Jenkinsfile?

            Show
            abayer Andrew Bayer added a comment - Can you share your Jenkinsfile ?
            Hide
            gkrupa Gerard Krupa added a comment -

            The following project will demonstrate the issue: https://github.com/GJKrupa/JENKINS-45616

            Show
            gkrupa Gerard Krupa added a comment - The following project will demonstrate the issue:  https://github.com/GJKrupa/JENKINS-45616
            Hide
            jglick Jesse Glick added a comment -

            Probably not a bug. Cf. JENKINS-41339.

            Show
            jglick Jesse Glick added a comment - Probably not a bug. Cf. JENKINS-41339 .
            Hide
            gkrupa Gerard Krupa added a comment -

            Looks like the same issue and like the last commenter on that ticket I'm looking for a way to append to prepend to PATH globally for the instance rather than defining it for every job.  Our Jenkins runs as a service and for various reasons, SSH'ing into the box to modify /etc/sysconfig/jenkins whenever PATH needs to be updated isn't an option.

            Show
            gkrupa Gerard Krupa added a comment - Looks like the same issue and like the last commenter on that ticket I'm looking for a way to append to prepend to PATH globally for the instance rather than defining it for every job.  Our Jenkins runs as a service and for various reasons, SSH'ing into the box to modify /etc/sysconfig/jenkins whenever PATH needs to be updated isn't an option.
            Hide
            jglick Jesse Glick added a comment -

            Prefer PATH+FOO syntax, or better yet do any customizations you need using withEnv rather than messing with global configuration.

            Show
            jglick Jesse Glick added a comment - Prefer PATH+FOO syntax, or better yet do any customizations you need using withEnv rather than messing with global configuration.

              People

              • Assignee:
                Unassigned
                Reporter:
                gkrupa Gerard Krupa
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: