47

I am trying to modify PATH in jenkins master node (i have no slaves).From "Global Properties -> Environment Variables" i add 2 entries: "PATH" with value "$PATH:/opt/foo" and "FOO" with value "BAR". Now when i run my free style job with execute shell build step being "echo $PATH; echo $FOO" i see that PATH was not modified whereby FOO is displayed correctly. Why is that? Is there any way to modify PATH from jenkins global configuration ? I managed to modify PATH on a job level via EnvInject plugin but what i am really looking for is to modify PATH for all jobs.

1

5 Answers 5

48

You are doing it right. The same Manage Jenkins => Global Properties => Environment variables works for me.

Please note that if you have the EnvInject plugin installed, it seems to mask the environment variables from Jenkins global configuration. So uninstall EnvInject and try again.

Sign up to request clarification or add additional context in comments.

6 Comments

I do have it EnvInject plugin installed so you maybe right that it can interfere with env properties global jenkins setting. I will give it a try on Monday.
Thank you very much you I spent 4 hours trying to figure out what's wrong! It was EnvInject plugin.
you should also pay attention to the node properties, click on your build node, then configure and check what's define in Environment variables
Check how your changes affect /systemInfo
For me, setting an environment variable in Jenkins at /configure works BUT watch out for these: 1) /systemInfo will show the old PATH, 2) the job itself will show PATH = $PATH:/new/path & will not be expanded, even though it is during runtime, 3) echo $PATH in the freestyle job will show the wrong path. Lastly, if it isn't working try prepending instead of appending, e.g. /new/path:$PATH. I do have EnvInject plugin installed.
|
24

Jenkins also supports the format PATH+<name> to prepend to any variable, not only PATH:

Jenkins variable + notation

This is also supported in the pipeline step withEnv:

node {
  withEnv(['PATH+JAVA=/path/to/java/bin']) {
    ...
  }
}

Just take note, it prepends to the variable. If it must be appended you need to do what the other answers show.

See the pipeline steps document here.

You may also use the syntax PATH+WHATEVER=/something to prepend /something to $PATH

Or the java docs on EnvVars here.

Comments

16

Running Jenkins 2.150.1 on Mac OS X installed with homebrew. I couldn't get the PATH environment to change by updating the PATH environment variable as described in some of the other answers here and on similar questions. In the end I updated the Jenkins installation's plist. I added the following to /usr/local/Cellar/jenkins-lts/2.150.1/homebrew.mxcl.jenkins-lts.plist:

<key>EnvironmentVariables</key>
<dict>
  <key>PATH</key>
  <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>

And then restarted the service:

brew services restart jenkins-lts

2 Comments

Great and worked for me. Feel like the other PATH mods are really not as good as this for Brew OSX.
I’ve tried many other steps including those upvoted more but this somehow worked for me and I thank you for this sir
12

I was facing the same problem as my wsimport command was not being picked up by Jenkins master. This comes with Java, so I waned to append JAVA_HOME/bin to the PATH variable in jenkins master.

Environment name should be Path and not PATH. Please see attached image for the same, where I have ammeneded JAVA_HOME/bin to PATH variable enter image description here

1 Comment

This approach applies only for the Freestyle projects. If you work with declarative pipeline follow instructions here: stackoverflow.com/questions/43987005/…
4

When appending to PATH variable through Jenkins (Manage Jenkins => Global Properties => Environment variables), use "Path", not "PATH" for the variable name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.