Day 28 Task: Jenkins Agents

Day 28 Task: Jenkins Agents

·

3 min read

👉 Introduction📜

In our Jenkins journey, we've explored the role of the Jenkins Master (Server) in orchestrating our CI/CD pipelines. Today, we dive into Task-02: Jenkins Agent, a crucial aspect for scaling our Jenkins infrastructure.

Task-01: Jenkins Master (Server)

Before we venture into agents, let's briefly recap the importance of the Jenkins Master. It serves as the command center, coordinating and managing tasks across various nodes or agents.

Task-02: Jenkins Agent

Jenkins Agents are worker machines that perform build and deployment tasks based on the instructions received from the Master. This distributed architecture allows for scalability and efficient resource utilization.

Task-03:

Task-3.1: Create an agent by setting up a node on Jenkins

To add an agent, we set up a new node on Jenkins, defining its characteristics and capabilities.

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.

Create 2 EC2 instances for master and agent

Generate SSH keys on “Jenkins-server” by running

“ssh-keygen”

Now go to the “.ssh” folder and there will be public and private keys in Jenkins-server.

Go to Jenkins-agent, Add public key from “Jenkins-master” to “Jenkins-agent” under location “.ssh/authorized_keys”

Now, go to the Jenkins dashboard, and click on “Manage Jenkins”.

Now, click on “Manage Nodes and Clouds”

Now, click on “+ New Node”

Add details of your second node, accordingly.

Create your first agent.

Add details of your node, accordingly.

Select the launch method as “Launch agents via SSH”. Give the public IP of an agent in the host field.

Click on “Add” under Credentials.

Add the private key that we created in the 'jenkins-master' instance using ssh-keygen.

Click on 'save' that will create a node. You can see agent will be connected and online.

Your agent is made.

Task-04:

Task-4.1: Run your previous Jobs (which you built on Day 26 and Day 27) on the new agent

The difference will be here in the pipeline script i.e.

agent: we have specified the agent on which we want to deploy.

"agent-1"

Click on Save, and your project will be tied to 'agent-1'.

Task-4.2: Use labels for the agent; your master server should trigger builds for the agent server.

Implemented labels to categorize and streamline job execution. Let your master intelligently trigger builds on the designated agent based on these labels.

now, run the job.....

build now,

Check output,

check if the application is running successfully........

OSm, the application running fine.

👉 Conclusion💥

In conclusion, understanding and implementing Jenkins Agents is a pivotal step in optimizing your CI/CD pipeline. The ability to distribute tasks among agents enhances efficiency and resource utilization, leading to a more robust and scalable Jenkins infrastructure.

So, gear up and let your Jenkins environment flourish with the power of distributed agents! 🚀

Â