Pages

Sunday, December 27, 2015

Distributed Building aka Master - Slave in Jenkins

Jenkins besides acting a Continuous integration tool, it allows other configuration options which helps developers in many ways. One such facility provided by Jenkins is the configuration of the master-slave.

The most basic installation contains one Jenkins node called master operating itself. This master handles all the tasks for your build system. The slave can be taught as another Jenkins process which does the build jobs on  behalf of the master.

In most cases installing a slave doesn't change the behavior of the master. It will serve all HTTP requests, and it can still build projects on its own.

If we remember a executer is the one that does building the jobs in a parallel way. These executors can be created dynamically to run light weight jobs used mostly for the orchestration purposes. Once you install a few slaves you might find yourself removing the executors on the master in order to free up master resources.

Slaves are computers that are set up to build projects for a master. Jenkins runs a separate program called "slave agent" on slaves. When slaves are registered to a master, a master starts distributing loads to slaves. Term Node is used to refer to all machine that are part of Jenkins grid, slaves and master.

The exact delegation behavior depends on the configuration of each project; some projects may choose to "stick" to a particular machine for a build, while others may choose to roam freely between slaves.   
Since each slave runs a separate program called a "slave agent" there is no need to install the full Jenkins (package or compiled binaries) on a slave. There are various ways to start slave agents, but in the end the slave agent and Jenkins master needs to establish a bi-directional communication link (for example a TCP/IP socket.) in order to operate.

In this article we will see how we can configure Jenkins Slaves for distributed build management in our local environment. The same thing can be done with remote machines too. 

1) Go to the Manage jenkins -> Manage Nodes. We see a master Node being added on the left hand pane. This is the only node available at this moment to process the request like build.

2) Click on the new Node. On the left pane
Enter the Name you want for the new Node “slave”. Choose the Node to be a Dumb Slave. As said in the screen it self a Dumb slave does not provide any high level of integrations with any other slaves.

3) Now once the Dumb slave is created, click on the newly created slave to configure that. We need to configure the dumb slave
 Enter the Label of the slave as “slaveNode”. The label is very important for the slave. The same label will be used when distributing build to the slave nodes.
The launch Method is one very important element that defines how the node will be configured. The launch method contains,
Launch Slave Agents on UNix Machine via SSH
Launch Slave Agents via Java web Start
Launch Slave Via execution of command on the Master
Let jenkins control this windows slave as a windows service

We will be choosing the Launch slave via java web Start since we are doing this on our local machine. Java Web Start (also known as JavaWS, javaws or JAWS) is a framework developed by Sun Microsystems (now Oracle) that allows users to start application software for the Java Platform directly from the Internet using a web browser. Choose other options based on your requirement. Most cases in production environment we will be choosing “Launch  slave agents on unix Machine via SSH”
Now save the changes. Once the changes are completed we see the slave added to the Node Dashboard

At this moment the slave1 created is not active. We can see a red mark on that. Now click on the Slave1 and we can see that Launch button available.
Click on the launch button which will invoke a java web start slave agent like below,
Once the status on the dialog box shows as connected we can see the status of the Slave on the Node Dashboard as Active like below,
Now once the Slave agent is active we need to make a job run the Slave Node. For this Choose a Job already configured or configures a new one and go to the configuration for that job.Check the "Restrict where this project can be run" then we will see a Text box  under where we need to enter the Label expression which is the name of the Slave label that we created earlier. Enter label of the slave we created “slaveNode”. Now we can see a test saying "Label is serviced by 1 node" and click Ok
Now when we run the build , we can see
Building Remotely on slave1 (slaveNode1)  in workspace /opt/jenkins....
This is how we can configure the Master -salve nodes of jenkins in localhost

We can see the below output too,


No comments :

Post a Comment