« »
5/06/2016

How to start a Jenkins slave inside Docker

First thing first: open Jenkins, go to Settings > Build Nodes > Add new node > Select Permanent Agent, then set the distant workspace directory (our HOST_JENKINS_SLAVE_HOME in the script above) and select Launch agent via Java Web Start.

Finally, login into your slave machine, put and edit the script above, run it and job done!

#!/usr/bin/env bash
JENKINS_ENDPOINT="http://my-jenkins.com"
SLAVE_SECRET="YOUR_SLAVE_SECRET_FROM_JENKINS_NODE_SETTINGS"

# where your slave working dir will be, it should be the same as the one you configured in Jenkins master settings
HOST_JENKINS_SLAVE_HOME="/data/jenkins-slave"

# download the slave.jar on the slave machine
curl -s "${JENKINS_ENDPOINT}/jnlpJars/slave.jar" > slave.jar

# run the slave inside a docker
# replace "-d" by "-it --rm" for debugging
docker run -d --name jenkins-slave -v ${PWD}:/app -v ${HOST_JENKINS_SLAVE_HOME}:${HOST_JENKINS_SLAVE_HOME} java:7 java -jar /app/slave.jar -jnlpUrl "${JENKINS_ENDPOINT}/computer/docker-slave/slave-agent.jnlp" -secret $SLAVE_SECRET
« »
 
 
Made with on a hot august night from an airplane the 19th of March 2017.