Recently, I set up Jenkins on my machine and it was not a trivial task. Therefore, this post will serve me as a memo for later.
- Get jenkins.war and put it somewhere. In my case,
/opt/bin - Create a dedicated user who will run Jenkins
- Find out free UniqueID and PrimaryGroupID using
dscl . -list /Users UniqueID dscl . -list /Groups PrimaryGroupID
In my case503was free. - Create the group and user “jenkins”
dscl . -create /Groups/jenkins dscl . -create /Groups/jenkins PrimaryGroupID 503 dscl . -create /Users/jenkins dscl . -create /Users/jenkins UserShell /usr/bin/false dscl . -create /Users/jenkins RealName "Jenkins" dscl . -create /Users/jenkins UniqueID 503 dscl . -create /Users/jenkins PrimaryGroupID 503
- Set the home of the jenkins user
dscl . -create /Users/jenkins NFSHomeDirectory /opt/var/jenkins
- Find out free UniqueID and PrimaryGroupID using
- Copy the following runner script to somewhere. I put it in
/opt/bin/jenkins-runner.sh. This script is from the Mac installer of Jenkins.#!/bin/bash # # Startup script used by Jenkins launchd job. # Mac OS X launchd process calls this script to customize # the java process command line used to run Jenkins. # # Customizable parameters are found in # /Library/Preferences/org.jenkins-ci.plist # # You can manipulate it using the "defaults" utility. # See "man defaults" for details. defaults="defaults read /Library/Preferences/org.jenkins-ci" war=`$defaults war` || war="/Applications/Jenkins/jenkins.war" javaArgs="" heapSize=`$defaults heapSize` && javaArgs="$javaArgs -Xmx${heapSize}" home=`$defaults JENKINS_HOME` && export JENKINS_HOME="$home" add_to_args() { val=`$defaults $1` && args="$args --${1}=${val}" } args="" add_to_args prefix add_to_args httpPort add_to_args httpListenAddress add_to_args httpsPort add_to_args httpsListenAddress add_to_args ajp13Port add_to_args ajp13ListenAddress echo "JENKINS_HOME=$JENKINS_HOME" echo "Jenkins command line for execution:" echo /usr/bin/java $javaArgs -jar "$war" $args exec /usr/bin/java $javaArgs -jar "$war" $args - Create a property list for Jenkins
defaults write /Library/Preferences/org.jenkins-ci war /opt/bin/jenkins.war defaults write /Library/Preferences/org.jenkins-ci JENKINS_HOME /opt/var/jenkins defaults write /Library/Preferences/org.jenkins-ci heapSize 512m defaults write /Library/Preferences/org.jenkins-ci httpPort 8447
- Create a launch daemon for Jenkins and save it as
/Library/LaunchDaemons/org.jenkins-ci.plist. You must change the owner of this file toroot. The following is also from the Mac installer of Jenkins.<?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>/opt/var/jenkins</string> </dict> <key>GroupName</key> <string>jenkins</string> <key>KeepAlive</key> <true/> <key>Label</key> <string>org.jenkins-ci</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/opt/bin/jenkins-runner.sh</string> </array> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>jenkins</string> </dict> </plist>
- Start Jenkins using
launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist
and go tohttp://localhost:8447 - If something does not work, stop Jenkins using
launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
and … here the magic happens … and start it again. :)