Sales +1-855-261-3391 Chat Blog Partner Support Status  |  Download

Networking Unplugged

Perspectives on cloud networking and software-defined WANs

Posted July 29, 2014
Comments 0 Comments

Secure Cloud Bursting (Part 2): How to Build a Jenkins Slave and Attach it to the Master

If you joined me last week for part one of this four part Secure Cloud Bursting series, you know that a lot of companies pay for unused cloud build infrastructure. Here at Pertino, we found out that we were paying approximately $6,000/month for unused capacity. This just didn’t sit right with me, so I sat down to figure out how we could pay for only the build capacity we use at any given time.

Using Pertino in conjunction with Jenkins and Docker, we engineered a way to securely cloud burst, maximizing cost efficiency and reducing infrastructure complexity. In layman’s terms, we can actually save you that $6,000/month.

Our first post explained how to build a Jenkins Master—step one in the secure cloud bursting process. If you missed that post, you will want to go back and catch up on the steps before beginning the below. This post will review how to build a Jenkins Slave and connect it back to the Master, and the last two posts will walk you through deploying a Jenkins Slave to a secure cloud and performing a Jenkins initiated cloudburst.

Note: Some of you may know that Docker can run within Docker. In this post, we are going to build a Jenkins Slave that is a Docker container and has the ability to create other Docker containers. Dockerception. This is especially useful if you deploy your app in containers.

I. Build a Jenkins Slave Container

1. In your base subdirectory (demo), make a subdirectory named Jenkins-Slave.

mkdir jenkins-slave

2. Now, change your current directory to the Jenkins-Slave subdirectory you just made.

cd jenkins-slave

3. Into your Jenkins-Slave subdirectory, copy the text from Pertino supplied Dockerfile. The file explains what each line of code will do.

4. Copy the text from Pertino supplied into your Jenkins-Slave subdirectory.

5. Copy the text from Pertino supplied wrapdocker into your Jenkins-Slave subdirectory.

6. Copy the text from Pertino supplied supervisord.conf into your Jenkins-Slave subdirectory.

7. Make and wrapdocker executable.

chmod +x wrapdocker

8. Now, find the IP address of the Jenkins Master container (assuming you only have the Jenkins Master running).

sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(sudo docker ps -l -q)

Note: The remainder of this post will only work if you have your Jenkins Master and jenkins Slave containers running in the same Docker environment.

Find Jenkins Master Container IP

9. Edit “run_slave” on the line buildhost = “http://<yourhost>:8080”. Replace <your host> with the IP address from the previous step.

Your Host

10. Now, build the Container.

sudo docker build -t jenkins-slave .

II. Attach the Jenkins Slave to the Master

1. Navigate to the Jenkins webpage (http://localhost:8080).

2. Click Manage Jenkins.

3. Click Manage Nodes.

4. Click New Node.

5. Name your Node "slave-ubuntu". (note: ubuntu is the hostname of your computer running docker)

6. Select Type Dumb Slave.

7. Click OK.

8. You must enter a Remote Root Directory. Enter: "/home/jenkins".

9. Type "StandardSlave" in Labels.

10. For your Launch Method, select launch slave agents via Java Web Start.

11. Click Save.

III. Run the Jenkins Slave

1. Run the Jenkins Slave Container.

sudo docker run --privileged -p 9022:22 -d -h ${HOSTNAME} jenkins-slave

2. Enter your superuser password.

3. Verify that the Jenkins Slave is running.

sudo docker ps

Verify Jenkins Slave

4. Verify connectivity.

a. Navigate to the Jenkins webpage (http://localhost:8080).

b. Click Manage Jenkins.

c. Click Manage Nodes.

d. Click on slave-ubuntu. Confirm it is connected via JNLP agent.

Verify Slave Connectivity


Note: Our container is low on space. This is OK for now because we will resolve the space issue with a dynamic slave in the third blog. Or, you can deploy to a machine with more resources.

5. Click Bring this node back online.

Now you can run a test job on your Jenkins-Slave.

IV. Run a test job on your Jenkins-Slave

1. Navigate back to the Jenkins home webpage (http://localhost:8080).

2. Click New Item.

3. Name your item "Test job".

4. Select Build a free style software project.

Build a free-style software project

5. Click OK.

6. Select Restrict where this project can be run and enter label "StandardSlave".

7. Scroll down to build and click Add build step.

8. Select Execute shell.

9. Enter "docker -- version". This will prove that the correct Docker version is running on your Jenkins Slave and will only work on that Jenkins Slave, not the Master.

10. Click Save.

11. Navigate back to the Jenkins home webpage (http://localhost:8080).

12. Click on Test Job.

13. Click on Build Now.

14. A build will now show in your build history. Click on this build.

15. Click on Link console output.

16. You should see the following successful build.

Successful Build

Congratulations! You've now successfully built a Jenkins Master and a Jenkins Slave and attached the Jenkins Slave to the Master—the first two steps in our secure cloud bursting process. Stay tuned for part 3—How to Deploy a Jenkins Slave to a secure cloud.


Luke Woydziak

Luke Woydziak

Networking Team Lead

Pertino is my seventh tech company, and I've loved every minute of it. After a career as a professional Track and Field Athlete, I've taken my passion and energy and directed it toward building and leading a team that solves complex engineering problems.

comments powered by Disqus
Chat now Click to Chat