Jenkins Configure Master and Slave Nodes
By: Rohit Raut
Tags: Cicd Tools, Master Slave, Automation, Jenkins

What is Jenkins?

Jenkins is an open-source automation tool written in java that automates some of the software development lifecycle tasks like build, test, deploy, and more. In this article, we will discuss how to configure Jenkins master-slave setup also called master-slave or master-agent architecture.

Need of Jenkins Mater-[Agent-slave] Architecture.

When we build the Jenkins job in a single Jenkins master node then Jenkins uses the resource of the base machine and If no executor is available then the jobs are queued in the Jenkins server. Sometimes you might need several different environments to test your builds. This cannot be done by a single Jenkins server. It is recommended not to run different jobs in the same system that required a different environment. In such scenarios where we need a different machine with a different environment that takes the specific job from the master to build.

On the same Jenkins setup, multiple teams are working with their jobs. All jobs are running on the same base operating system and the base operating system has limited resources. Also, we don't want to put our personal data on the same system where other teams can read.

Jenkins Distributed Architecture

Jenkins uses A Master-Slave architecture to manage distributed builds. The machine where we install Jenkins software will be Jenkins master and that run’s on port 8080 by default. On the slave machine, we install a program called Agent. This agent requires JVM. This agent executes the tasks provided by Jenkins master. We can launch n numbers of agents and we can configure which task will be run on which agent server from Jenkins master by assigning the agent to the task.

There are multiple ways to Install Agent in this article we will see the following.

Launching Agent with SSH from Master. Launch Agent by connecting it to master.

Launching Agent with SSH from Master.

For this first we need to install Plugins in Jenkins and Plugin name is

Install java first in slave Node.

The Next Steps are-

Click on Manage Jenkins

Click On Manage Nodes and Clouds

Click on New Node

Here add your slave name eg. Jenkins slave1

Permanent Agent:

Jenkins has two types of agents 1. On-Demand or Dynamic Agent Also called Dynamic Provisioning (Automatically launch when new Job is assigned) 2. Always on or Permanent Agent (Static Agent).

select Permanent Agent and Press OK

Give Name, permanent Agent, and Click OK

Slave Information

Executors: This number represents at a single point in time how many different jobs can run in parallel.

Remote root directory: This is the workspace directory for the agent where it stores data downloaded by the Job.

Label: This label is very important. with the help of this label, we can explicitly tell the job where you have to run.

In the launch method we have to choose “Launch agent via SSH” and to connect via ssh we required an IP address, user name, and password.

Host Key Verification Strategy: If you are connecting the first time via ssh from this system then choose no verification. That's all we have to do.

If you check the logs you will see the below output.

Agent successfully connected and online

Agent is online

Launch Agent by connecting it to master.

Here we will connect windows as a Jenkins slave. for windows, we have to use the JNLP protocol. JNLP(JAVA NETWORK LAUNCH PROTOCOL) is used to connect to Jenkins from a remote location

Just follow the same steps as above and change is only in Lanch Method. choose “Launch Agent by Connecting it to master”

Click on save

In the same directory, where you have downloaded the agent you have to run the command.