« »

How to start a Jenkins slave inside Docker while still exposing docker-cli to jobs

Running a jenkins slave inside docker is more often than not good enough, you may want to run jenkins jobs that requires docker cli. I just release a docker image that does just that.

  • Go to Jenkins > manage > node management
  • Click Create a node
  • Check Permanent Agent
  • Set working directory to something like /data/jenkins-slave (if you specify something else, don't forget to also change the command below)
  • Save
  • Download slave-agent.jnlp, open it to retrieve your secret
  • Change the command below with the working directory you specified, your slave-agent URL and jenkins secret
docker run --rm \
-v /data/jenkins-slave:/data/jenkins-slave \
-v /var/run/docker.sock:/var/run/docker.sock \ 
--rm fgribreau/jenkins-slave:latest java -jar /app/slave.jar \ 
-jnlpUrl "http://YOUR_OWN_JENKINS.com/computer/SLAVE_NAME/slave-agent.jnlp" \
  • Run it
  • Done 👍

Why is this awesome?

Now that I can use docker directly from Jenkins jobs, it means I can setup cron jobs through jenkins just with configuration. Since one of docker sweet point is the ability to run CLI tools without any more setup that downloading an image, I now can setup nightly elastic/curator cron jobs just from Jenkins interface without the initial overhead of environnement setup.

I get fail build notifications directly from Hipchat (always be proactively alerted when something goes wrong!), traceability (who started the job) and of course I can reuse my Jenkins authorization setup for cron job as well. Thus no need to setup something like Rundeck when Jenkins already handles the feature set I want!

« »
Made with on a hot august night from an airplane the 19th of March 2017.