Jenkins is an open source automation tool written in Java with plugins built for Continuous Integration purpose. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. In this blog, I am going to talk about the Jenkins Master and Slave architecture.
I am going to cover the below pointers:
- What is Jenkins?
- Jenkins Architecture
- How does Jenkins Master Slave architecture work?
- Setting up Slaves with Jenkins Master
So let us begin with our first topic.
What is Jenkins?
As described earlier, Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.
With Jenkins, developers can trigger a build and test for each and every change made in the source code. Therefore, Jenkins tool is used in CI. It is the most mature CI tool possible.
Jenkins achieves Continuous Integration with the help of plugins. Plugins are the primary means of enhancing the functionality of a Jenkins environment to suit organization- or user-specific needs. There are over a thousand different plugins, which can be installed on a Jenkins master and to integrate various build tools, cloud providers, analysis tools, and much more.
Advantages of Jenkins include:
- Jenkins is an open source tool with much support from its community.
- Installation is easier.
- It has more than 1000 plug-in to make the work easier.
- It is easy to create new Jenkins plugin if one is not available.
- It is a tool which is written in Java. Hence it can be portable to almost all major platforms.
Jenkins Architecture
The main function of Jenkins is used to execute predefined steps such as compile java code, build war.You can trigger build on time basis or event basis. for example: every 15 mins or new commit in the git.
Some of the steps executed by Jenkins are:
- Build the project with help of maven or gradle.
- Run the test automatically and generate test report.
- Execute any shell script.
- Execute any batch file.
- Sometimes you might need several different environments to test your builds. This cannot be done by a single Jenkins server.
- If larger and heavier projects get built on a regular basis then a single Jenkins server cannot simply handle the entire load.
To address the above-stated needs, Jenkins distributed architecture came into the picture.
Jenkins Distributed Architecture
Jenkins uses a Master-Slave architecture to manage distributed builds. In this architecture, Master and Slave communicate through TCP/IP protocol.
Master:
- Schedule build jobs
- Distribute the jobs to slaves
- Monitor the slaves and get the build results
- It can also execute build directly
Slave:
- Build the job distributed by Master.
- Jenkins starts a separate program named “slave agent”.When slaves are subscribed to master, master starts distributing work to slaves.
The diagram below is self-explanatory. It consists of a Jenkins Master which is managing three Jenkins Slave.
How Jenkins Master and Slave Architecture works?
Now let us look at an example in which we use Jenkins for testing in different environments like Ubuntu, MAC, Windows, etc.
- Jenkins checks the Git repository at periodic intervals for any changes made in the source code.
- Each builds requires a different testing environment which is not possible for a single Jenkins server. In order to perform testing in different environments, Jenkins uses various Slaves as shown in the diagram.
- Jenkins Master requests these Slaves to perform testing and to generate test reports.
How to setup Jenkins Master and Slaves?
- Go to the Manage Jenkins section and scroll down to the section of Manage Nodes.
2. Click on New Node
3. Give a name for the node, choose the Permanent Agent option and click on Ok.
4. Enter the details of the node slave machine. Here no. of executors is nothing but no. of jobs that this slave can run parallel. Here we have kept it to 2. The Labels for which the name is entered as “Slave1” is what can be used to configure jobs to use this slave machine.Select Usage to Use this node as much as possible. For launch method we select the option of “Launch agent via SSH”. Provide the ssh credentials and save. We can have ssh key verification enabled. Here We have provided No Host key verification. In Availability select “Keep this agent online as much as possible”.Click on Save.
Once you complete the above steps, the new node machine will initially be in an offline state but will come online if all the settings in the previous screen were entered correctly. We can check this in the slave log. We get "Agent successfully connected". One can at any time make the node slave machine offline if required.
5. Now since your slave is up and running, lets execute a job on slave. For that I already have an existing job and I will run this job on this slave. Open this job and click on configure. Now here in the General section, click on “Restrict where this project can be run”. Here in Label Expression, enter the name of the slave and save it. Now click on Build now and see the output of this job. Everything is correct you will see the output as Success.
So with this, we have come to the end of this blog on Jenkins Master and Slave Architecture. I hope you have understood all the concepts explained here.
No comments:
Post a Comment