How to Run Jenkins slaves on Docker

Posted By : Jatin Gupta | 30-Jul-2018

Jenkins is most well known an open source automation server written in Java. It has numerous fascinating modules and highlights. Today, I will demonstrate you one of them – how to set up Jenkins master server with one slave associated with it. With the goal that we will have the capacity to run distributed builds using few containers. For that example we utilize docker images of (jenkins) and Jenkins slave (jenkinsci/jnlp-slave). How about we begin from running Jenkins docker container.

docker run -dit --name jenkins -p 8080:8080 -p 50000:50000 jenkins

Go to jenkins console (http://localhost:8080) and select Manage Jenkins - > Manage Nodes and after that select New Node.

In the following page you need to put the slave name – for that example is slave1.
Subsequent to clicking OK you will see new node on the rundown. Presently, you can configure it by clicking setting tab.

 

 
New node is made but is yet disabled. In the wake of clicking node you will see the page with points of interest.
The important data is in command secret. Save that token.
 
Presently, we will run docker image with JNLP agent. In the docker run we enter Jenkins master URL, secret token and picked node name (slave1). On the off chance that you might want to set up it without docker you ought to download slave specialist JAR document by clicking Launch tab and run agent from CLI like in the photo above.
 
docker run -dit --name jenkins-slave1 jenkinsci/jnlp-slave -url http://localhost:8080 250f30e4d2753263312b4fa3d3ca560cba02b010479874316901ed03a6df0660 slave1

After starting slave docker you can see name slave1 in the Build Executor Status beneath master node.

 

We can also run stages on this node using pipeline as code, 

node('slave-1') {
    stage('Checkout') {
       ...
    }
    stage('Build') {
       ...
    }
}

This will run both the stages on node "slave1" rather than running them on master node.

 

About Author

Author Image
Jatin Gupta

Jatin is a DevOps trainee. He ha deep interest in python and cloud technologies. He likes to read about science/history and fiction, listening to music and explore new places.

Request for Proposal

Name is required

Comment is required

Sending message..