20

I'm facing this weird problem , struggling to solve since almost couple of days.

Working: On mac mini command prompt , I switch to jenkins user and can run docker command without any problem.

Not Working: but when I run a jenkins job , inside shell command step docker is not recognized.

I'm getting error

docker: command not found

docker --version

But mentioning explicit path of docker , does work

/Users/buildserver/Library/Group\ Containers/group.com.docker/bin/docker --version

Question : Why docker command can't look into correct path ?

Permissions

lrwxr-xr-x 1 buildserver staff 71 Oct 14 10:44 docker -> /Users/buildserver/Library/Group Containers/group.com.docker/bin/docker

jenkins uses is part of staff group.

Thanks in advance.

Regards, Vikram

vikramvi
  • 3,312
  • 10
  • 45
  • 68
  • 1
    Try echoing and verifying $PATH within the Jenkins job. It's most probably different than on your shell prompt. – Misko Oct 14 '16 at 12:35

3 Answers3

46

For others (Late but worthy), I installed Jenkins via Brew, so I add Docker's path to the file below: /usr/local/Cellar/jenkins-lts/2.176.3/homebrew.mxcl.jenkins-lts.plist (Whole file looks like below)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.jenkins-lts</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/libexec/java_home</string>
      <string>-v</string>
      <string>1.8</string>
      <string>--exec</string>
      <string>java</string>
      <string>-Dmail.smtp.starttls.enable=true</string>
      <string>-jar</string>
      <string>/usr/local/opt/jenkins-lts/libexec/jenkins.war</string>
      <string>--httpListenAddress=127.0.0.1</string>
      <string>--httpPort=8080</string>
    </array>
    <key>RunAtLoad</key>
    <true />
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin/:/Users/Kh0a/Library/Group\ Containers/group.com.docker/Applications/Docker.app/Contents/Resources/bin</string>
    </dict>
  </dict>
</plist>

Then restart Jenkins' service:

brew services restart jenkins-lts

More question

Samuel Hawksby-Robinson
  • 2,652
  • 4
  • 24
  • 25
Khoa
  • 1,738
  • 1
  • 14
  • 21
  • 1
    As mentioned by [Alexander Yalunin](https://stackoverflow.com/users/7508493/alexander-yalunin) [here](https://stackoverflow.com/a/58688597/11031425), the new directory in Mac should be `/opt/homebrew/Cellar/jenkins-lts/2.387.1/homebrew.mxcl.jenkins-lts.plist` – Faris Durrani Mar 31 '23 at 18:07
  • `Kh0a` has to be replaced with the actual user in your machine - `/Users/{replace with your user}/Library/Group\ Containers`, or use env variable to grab it dynamically - `$USER` – Addis Jul 15 '23 at 17:29
4

The PATH which Jenkins jobs start with isn't the same as the path which the Jenkins user sees in bash. In the Jenkins UI you can edit the environment varables (from Manage Jenkins/Configure System), and add the Docker folder to PATH:

PATH -> $PATH:/Users/buildserver/Library/Group\ Containers/group.com.docker/bin/

Some more detail in the answer to this question.

Community
  • 1
  • 1
Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
  • + echo '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/local:/Users/buildserver/Library/Group\' Containers/group.com.docker/bin/ /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/local:/Users/buildserver/Library/Group\ Containers/group.com.docker/bin/ + whoami jenkins + docker --version /Users/Shared/Jenkins/tmp/hudson4594253879036703398.sh: line 4: docker: command not found – vikramvi Oct 14 '16 at 13:53
  • 1
    I got it fixed with PATH=$PATH:/Applications/Docker.app/Contents/Resources/bin/ which docker /usr/local/bin/docker /Users/buildserver/Library/Group Containers/group.com.docker/bin/docker /Applications/Docker.app/Contents/Resources/bin – vikramvi Oct 14 '16 at 14:04
3

I have solved the above issue by updating the file

/usr/local/Cellar/jenkins-lts/2.176.3/homebrew.mxcl.jenkins-lts.plist. 

I have added the path of docker in the above file.

<key>EnvironmentVariables</key>
  <dict>
    <key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin/:/Users/admin/Library/Group\ Containers/group.com.docker</string>
  </dict>
Héctor Valverde
  • 1,089
  • 1
  • 14
  • 34
  • you may need to update `/Users/admin/Library/Group\ Containers/group.com.docker ` => `/Users/${USER}/Library/Group\ Containers/group.com.docker`. `${USER}` var may not get expanded in the plist. May need manual update there. – Robert Ranjan Dec 07 '21 at 22:39