Jenkins Agents which are also known as Jenkins Nodes are part
of Jenkins environment. We can utilize the agents or nodes for
performing the jobs, tasks, deployment, etc. Jenkins Server
works also as master while nodes or agents can work as slave.
Where Jenkins server control all the workflow which has been
defined to perform certain tasks.
If we talk in simple words Jenkins Server is a master node
which manages Jenkins environment and its agents are those
which is configured to perform tasks. The agent can be any
virtual machine, physical machine and even it can be a
container as well. So if you have created a job then it will
trigger on agent as per your definition.
The question arise why you need Jenkins Agents. The Simple
answer is when you are running a small environment then a
single Jenkins Server can manage all things. But when you are
going to manage it to a large scale you need agents which
holds the loads of builds etc. It distributes the load and
improve scalability as well.
Let’s add a Jenkins agent. Here are some basic steps to add a
node.
- Ensure java is installed on node.
- Create a user and provide sudo access to perform the task
(sudo is optional as per your requirementGo ahead and add node
via Jenkins GUI.
- Make a connection between Master and node using SSH or other
method.
My Jenkins server is “Jenkins.kb.com” and agent is “managed1.
kb.com”.
Check and install java on managed1 if not there.
# dnf install java-11-openjdk –y
Let’s create a user to make a connection between server and
agent. You can also create its key and make a connection.
# useradd -c "Jenkins Agent User" jenkins
# usermod -aG wheel jenkins
# id jenkins
uid=1012(jenkins) gid=1012(jenkins) groups=1012(jenkins),10(wheel)
# passwd jenkins
Here we will add via SSH connection.
Login to Jenkins Server and go to Manage Jenkins. Click on
nodes and then to New Node.
Put its name and Create. Go ahead and fill details. Below are
the details you need to know while creating an agent.
Name: Node name you want to add.
Description: You can put some information about node to
identify it.
Number of executors: This is basically use to perform the tasks
and it must be less than or equal to number of CPUs on agent.
Remote Root Directory: This path should be owned by Jenkins so
that everything you performed have a location.
Labels: This is basically used to tag used for multiple agents
grouping. If you want to run jobs to multiple agents then it
can be assigned to all via tagging.
Usage: It controls how Jenkins schedule jobs.
Launch method: It basically controls how Jenkins starts the
agent. We will be using “via SSH” so will add its credentials
as well. “via credentials options”.
Now after filling details just finish and wait for node to be
active.
You can see that “managed1” is active now. Go ahead and build
jobs on agent managed1.