Day 28 : Jenkins Agents


Jenkins Master (Server)
Jenkins’s server or master node holds all key configurations. Jenkins master server is like a control server that orchestrates all the workflow defined in the pipelines. For example, scheduling a job, monitoring the jobs, etc.
Jenkins Agent
An agent is typically a machine or container that connects to a Jenkins master and this agent that actually execute all the steps mentioned in a Job. When you create a Jenkins job, you have to assign an agent to it. Every agent has a label as a unique identifier.
When you trigger a Jenkins job from the master, the actual execution happens on the agent node that is configured in the job.
A single, monolithic Jenkins installation can work great for a small team with a relatively small number of projects. As your needs grow, however, it often becomes necessary to scale up. Jenkins provides a way to do this called “master to agent connection.” Instead of serving the Jenkins UI and running build jobs all on a single system, you can provide Jenkins with agents to handle the execution of jobs while the master serves the Jenkins UI and acts as a control node.
Pre-requisites
Let’s say we’re starting with a fresh Ubuntu 22.04 Linux installation. To get an agent working make sure you install Java ( same version as jenkins master server ) and Docker on it.
Note:- While creating an agent, be sure to separate rights, permissions, and ownership for jenkins users.
Task-01
Create an agent by setting up a node on Jenkins
Create a new AWS EC2 Instance and connect it to master(Where Jenkins is installed)
The connection of master and agent requires SSH and the public-private key pair exchange.
Verify its status under "Nodes" section.
For creating a node login into Jenkins. Go to Dashboard—> manage Jenkins—→ new node
Fill up the mentioned details for your new node
The no of executors will depend on the no of vcpu’s of your agent server. I have created server with only 1 vcpu therefore kept it as 1
Mention the remote root directory as the path you defined in agent server. Here I have created a directory in agent server and mentioned it’s path. Select the launch method as launch agent via ssh.
Mention the host as ip address as of second ec2 server and we will use another set of credentials by adding new credentials
Add the private key created in master server before we start working on pipeline
Click on save and see if the agent is created in node or not
Click on deploy agent and see if it is able to deploy without any issue or not
Now our agent is deployed successfully
How we established connectivity between master Jenkins server and Jenkins agent server
We created new ec2 server for Jenkins agent and installed java and docker into it.
We then logged into master server and generated a new key pair using command “ssh-keygen -t rsa” in .ssh folder
We then copied the public key from master server to agent server and tried to login into agent server from master server using command “ssh ubuntu@agentserverip”
Task-02
Run your previous Jobs (which you built on Day 26, and Day 27) on the new agent
Use labels for the agent, your master server should trigger builds for the agent server.
We will create a new pipeline and this time we will run our job on the new agent
This time we will use pipeline script from github i.e. pipeline script from scm
Click on apply and build this pipeline
Subscribe to my newsletter
Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
