I recently installed Jenkins, using Homebrew. I also installed Mercurial using Homebrew.
I can successfully clone an hg repo just fine - from Terminal. But if I try and do the same thing as part of a job in Jenkins, it fails.
So, in by job, I told Jenkins to run a shell script echo $PATH
. Sure enough, the path /usr/local/bin
is not there. If I execute the same command from Terminal, it's there.
So, what is the best way to modify PATH so that Jenkins is pulling the same PATH that I'm using, when I echo it from Terminal?
Note, Jenkins is running from the same user account that I'm logged into doing these tests, so I can't fathom why this is happening.
Browse to http://localhost:8080 (or whichever port you configured for Jenkins when installing it) and wait until the Unlock Jenkins page appears. From the Jenkins console log output, copy the automatically-generated alphanumeric password (between the 2 sets of asterisks).
For a new path to be added to PATH environment variable in MacOS just create a new file under /etc/paths. d directory and add write path to be set in the file. Restart the terminal. You can check with echo $PATH at the prompt to confirm if the path was added to the environment variable.
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.
In your launchd .plist file for Jenkins, you can set the PATH environment variable by using the following:
<key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>(insert your path value here)</string> </dict>
That should set the PATH to whatever you need.
For some reason, Jenkins doesn't keep /usr/local/bin in the PATH when connecting to a slave.
You can add it to the PATH either by
Adding an environment variable on the Node Configuration, or
Adding a .bashrc file on the user folder with
PATH="/usr/local/bin:${PATH}"
Note: The Mac client must be disconnected and then reconnected via the Jenkins web app after editing ~/.bashrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With