Skip to content

Jenkins Build Agent

Howard Pritchard edited this page Jan 29, 2018 · 12 revisions

These instructions are for setting up a new build agent on the community Jenkins server (jenkins.open-mpi.org).

  1. 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.
  2. Install the Jenkins agent (below)
  3. Verify the agent shows as "online" in the Jenkins Build Executor Status on https://jenkins.open-mpi.org/.

Linux (systemd)

  • 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
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

Linux (no root access)

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).

MacOS

  • 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

HTTP Proxy (esp. non-transparent) gotchas

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
Clone this wiki locally