Dan Morrow
Dan Morrow

Reputation: 4481

jenkins on Mac, PATH is not set right, no /usr/local/bin

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.

Upvotes: 44

Views: 35027

Answers (6)

Erkki Nokso-Koivisto
Erkki Nokso-Koivisto

Reputation: 1265

Manage Jenkins -> Configure System -> Environment variables -> Add

  • Name = PATH+EXTRA
  • Value = /usr/local/bin

enter image description here

Upvotes: 4

Maxime
Maxime

Reputation: 1222

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

Upvotes: 14

Mayank
Mayank

Reputation: 1051

There should be no space on either side of = in following PATH modification: PATH="/usr/local/bin:$PATH"

I added it to my pre-build step on Jenkins installed on macOS.

Upvotes: 3

Jordan
Jordan

Reputation: 4212

I found that even setting the PATH environment variable for the node didn't work for the hombrew Mercurial installation. The path WOULD get set, but only for the script build phase, not for the VCS checkout phase. Here's what I wound up doing.

  1. Go into Manage Jenkins -> Configure System
  2. Add a new Mercurial Installation
  3. Name it whatever you want (I named mine build-mac)
  4. For Installation Directory I put /usr/local
  5. The Executable parameter was pre-set to INSTALLATION/bin/hg, so I just left it at that.
  6. Everything else in here can be left blank
  7. Go into your job and edit the configuration
  8. Under Source Code Management set Mercurial Version to the mercurial installation you just added.
  9. Save
  10. $$$

Hope that helps anyone else running into this same problem, now that we're not allowed (by default anyways) to do anything inside of /usr/bin anymore. Previously I would have just symlinked hg there, but now with the new "System Integrity Protection" "feature", that's no longer as trivial of task, and even more difficult if your Mac slave is headless.

Upvotes: 4

cody
cody

Reputation: 3277

You can set PATH in launchd.conf file. See here for details. Note that man launchctl says that 'commands can be stored in $HOME/.launchd.conf or /etc/launchd.conf to be read at the time launchd starts', so you probably can create '.launchd.conf' in your home directory and use instructions from the link with this file. But as far as I know in launchd.conf file you can't add directory to PATH, you can just rewrite PATH.
You can also see here for the solution using /etc/paths.d directory

Upvotes: 3

gaige
gaige

Reputation: 17481

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.

Upvotes: 23

Related Questions