Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jenkins LaunchAgent and scripts for El Capitan
# Can be more or less complicated depending on your CLI needs.
export HISTCONTROL=erasedups
export HISTSIZE=5000
shopt -s histappend
export VISUAL=less
export EDITOR=vim
export GIT_EDITOR="${EDITOR}"
export CLICOLOR=1
export LSCOLORS=dxfxcxdxbxegedabagacad
### HOME BREW ###
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
### add /usr/libexec/ to path
export PATH=/usr/libexec:$PATH
### add ./ to path ###
export PATH=.:~/bin:$PATH
### RUBY ENV ###
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
if [ -d /usr/local/etc/bash_completion.d ]; then
. /usr/local/etc/bash_completion.d/git-completion.bash
. /usr/local/etc/bash_completion.d/git-prompt.sh
fi
#!/usr/bin/env bash
# Assumes Java 8
# Install to /Users/jenkins/bin/jenkins-runner.sh
source /Users/jenkins/.bashrc
war="/Applications/Jenkins/jenkins.war"
javaArgs="-Dfile.encoding=UTF-8 -Dhudson.util.ProcessTree.disable=true"
javaArgs="$javaArgs -XX:MetaspaceSize=1024m"
javaArgs="$javaArgs -XX:MaxMetaspaceSize=2048m"
javaArgs="$javaArgs -Xms512m"
javaArgs="$javaArgs -Xmx1024m"
javaArgs="$javaArgs -Djava.io.tmpdir=/Users/Shared/Jenkins/tmp"
export JENKINS_HOME="/Users/Shared/Jenkins"
echo "JENKINS_HOME=$JENKINS_HOME"
echo "Jenkins command line for execution:"
echo /usr/bin/java $javaArgs -jar "$war"
exec /usr/bin/java $javaArgs -jar "$war"
<?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>EnvironmentVariables</key>
<dict>
<key>JENKINS_HOME</key>
<string>/Users/Shared/Jenkins</string>
</dict>
<key>ProcessType</key>
<string>Interactive</string>
<key>LowPriorityIO</key>
<false/>
<key>Label</key>
<string>org.jenkins-ci</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Users/jenkins/bin/jenkins-runner.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/Shared/Jenkins/log/jenkins.log</string>
<key>StandardOutPath</key>
<string>/Users/Shared/Jenkins/log/jenkins.log</string>
<key>UserName</key>
<string>jenkins</string>
</dict>
</plist>

Jenkins

These are incomplete instructions; I don't have the time to reproduce the procedure exactly.

  1. Create a jenkins user. Make the user an admin.
  2. Use the official Jenkins installer from the jenkins.org website.

Setup the environment

# 1. Install /Users/jenkins/.bashrc and then symlink:

$ cd /Users/jenkins
$ ln -s .bashrc .bash_profile

# 2. Create the log file
$ touch Library/Logs/jenkins.log

# 3. Create the ~/bin/ dir and install the jenkins-runner.sh
$ chmod +x ~/bin/jenkins-runner.sh

# 4. Change permissions on /Application/Jenkins/
$ sudo chown -R jenkins:admin /Application/Jenkins

# 5. Remove the LaunchDaemon
$ sudo launchctl stop org.jenkins-ci
$ sudo launchctl unload -F /Library/LaunchAgents/org.jenkins-ci.plist

# 6. Find all the artifacts of the original install and remove.
* /Library/Application Support/Jenkins
* /Library/LaunchDaemons/org.jenkin-ci.plist
* There is preferences plist
* There is a run script

# 7. Install LaunchAgent
$ ls -al /Library/LaunchAgents/org.jenkins-ci.plist
-rw-r--r--  1 root  wheel  855 Nov 17 11:30 /Library/LaunchAgents/org.jenkins-ci.plist
$ sudo launchctl load -wF /Library/LaunchAgents/org.jenkins-ci.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.