Skip to content

Instantly share code, notes, and snippets.

@th3hunt
Last active July 19, 2017 13:41
Show Gist options
  • Save th3hunt/6a07ccc2ca5134cfd51cce749cb84ecb to your computer and use it in GitHub Desktop.
Save th3hunt/6a07ccc2ca5134cfd51cce749cb84ecb to your computer and use it in GitHub Desktop.
Jenkins LaunchAgent on OS X for user Hudson
#!/bin/bash
# Hook that runs right after login by loginhook.plist LaunchAgent
# Place in $HOME/.loginhook
# chmod 700 .loginhook
# Ignore "control-C" or any other signals that might try to prevent this script from running
trap '' 1 2 3 6 14 15
# Lock the screen so that password is required again
(sleep 1; exec "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession" -suspend)
exit 0
<!-- Execute .loginhook -->
<?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>loginhook</string>
<key>ProgramArguments</key>
<array>
<string>/Users/hudson/.loginhook</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
<!-- Launch Jenkins Agent as a LaunchAgent. launchd will keep this job running at all times -->
<!-- Configure autologin for hudson user -->
<?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>
<!-- make sure /var/log/jenkins-agent directory exists and user has can write to it -->
<key>StandardOutPath</key>
<string>/var/log/jenkins-agent/jenkins-agent.log</string>
<key>StandardErrorPath</key>
<string>/var/log/jenkins-agent/jenkins-agent.log</string>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.jenkins-agent</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-Duser.home=/Users/hudson</string>
<string>-jar</string>
<string>PATH TO SLAVE.JAR</string>
<string>-jnlpUrl</string>
<string>JNLP URL</string>
<string>-secret</string>
<string>JNLP SECRET</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment