-
Notifications
You must be signed in to change notification settings - Fork 864
Jenkins Build Agent
These instructions are for setting up a new build agent on the community Jenkins server (jenkins.open-mpi.org).
- Have Brian or Howard set up a new Builder in Jenkins. They'll need a node name (usually, the host name), the build root for Jenkins (where you want Jenkins to put all it's stuff), how many builds can occur on the builder at the same time, a general description of the system, and a point-of-contact email address.
- Install the Jenkins agent (below)
- Verify the agent shows as "online" in the Jenkins Build Executor Status on https://jenkins.open-mpi.org/.
- Create the user / home directory you want to use for Jenkins builds. We'll assume this is user
jenkins
and home directory/home/jenkins
. - Download https://jenkins.open-mpi.org/jenkins/jnlpJars/agent.jar and copy to
/home/jenkins/agent.jar
. - Copy the following script into
/etc/systemd/system/org.open-mpi.jenkins.service
:
[Unit]
Description=Open MPI Jenkins Build Agent
After=network.target auditd.service
[Service]
ExecStart=/usr/bin/java -jar /home/jenkins/agent.jar -jnlpUrl https://jenkins.open-mpi.org/jenkins/computer/MY_AGENT_NAME/slave-agent.jnlp -secret MY_AGENT_SECRET -workDir /home/jenkins
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=10
#RestartPreventExitStatus=255
Type=simple
User=jenkins
[Install]
WantedBy=multi-user.target
- Run
sudo systemctl enable org.open-mpi.jenkins.service
- Run
sudo systemctl start org.open-mpi.jenkins.service
- Output from the agent should be sent to syslog for debugging
Can you add a cron entry as the user you want to use to run Jenkins? If so, these instructions are for you (and assume that your user is someuser
).
- Create a the directory you want to use for Jenkins builds. We'll assume this is
/home/someuser/jenkins/
. - Download https://jenkins.open-mpi.org/jenkins/jnlpJars/agent.jar and copy to
/home/someuser/jenkins/agent.jar
. - Copy the following script to
/home/someuser/jenkins/agent-keepalive.sh
:
#!/bin/bash
JAR_NAME="agent.jar"
AGENT_NAME="MY_AGENT_NAME"
AGENT_SECRET="MY_AGENT_SECRET"
AGENT_WORK_DIR="/home/someuser/jenkins"
JAVA="java"
JCMD="jcmd"
RUN_COMMAND="$JAVA -jar "$JAR_NAME" -jnlpUrl https://jenkins.open-mpi.org/jenkins/computer/$AGENT_NAME/slave-agent.jnlp -secret $AGENT_SECRET -workDir $AGENT_WORK_DIR"
date >> $AGENT_WORK_DIR/agent.out
if ! $JCMD | grep $JAR_NAME > /dev/null ; then
echo "Restarting" >> $AGENT_WORK_DIR/agent.out
cd $AGENT_WORK_DIR
nohup $RUN_COMMAND >>$AGENT_WORK_DIR/agent.out 2>&1 &
fi
- Edit your personal crontab to run
/home/someuser/jenkins/agent-keepalive.sh
every 5-15 minutes (*/5 * * * * /home/someuser/jenkins/agent-keepalive.sh
should do the trick).
- Create a user for the jenkins builder (the rest of these instructions assume it's user
jenkins
with home directory/Users/jenkins
). - Download https://jenkins.open-mpi.org/jenkins/jnlpJars/agent.jar and copy to
/Users/jenkins/agent.jar
. - Copy the following startup script into
/Library/LaunchDaemons/org.open-mpi.jenkins.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.open-mpi.jenkins</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-jar</string>
<string>/Users/jenkins/agent.jar</string>
<string>-jnlpUrl</string>
<string>https://jenkins.open-mpi.org/jenkins/computer/MY_AGENT_NAME/slave-agent.jnlp</string>
<string>-secret</string>
<string>MY_AGENT_SECRET</string>
<string>-workDir</string>
<string>/Users/jenkins</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>jenkins</string>
</dict>
</plist>
- run
sudo launchctl load /Library/LaunchDaemons/org.open-mpi.jenkins.plist
If your system is sitting behind a non-transparent proxy, you may need to add some options to Java. For example:
java -Dhttps.proxyHost=proxyout.foolab.gov -Dhttps.proxyPort=8080 -jar agent.jar...
In cases where one is using the cron job approach outlined above to keep the agent alive, it may also be necessary to initialize the default login environment in the crontab entry, e.g.
*/5 * * * * . $HOME/.profile /home/someuser/jenkins/agent-keepalive.sh
At least on one system, it has been observed that across a reboot of the system, the cron job can try to restart the slave agent before the system's external network connectivity has been fully established. This can result in problems with the slave agent getting stuck in a loop trying to connect to the AWS jenkins server. Because the slave agent appears to be running correctly, the cron job doesn't kill the instance of the slave agent and try to restart. One workaround for this issue is to add the -noReconnect
argument to the slave-agent command line. This will result in the slave agent not trying to reconnect but to exit with error.