Day 28: Jenkins Agents | Master & Agent(Slave) Nodes

Day 28: Jenkins Agents | Master & Agent(Slave) Nodes

90DaysOfDevOps

·

3 min read

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.

How to Add Jenkins Slave to Master - FoxuTech

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 the master(Where Jenkins is installed)

  • The connection of the master and agent requires SSH and the public-private key pair exchange.

  • Verify its status under the "Nodes" section.

  • You can follow this article for the same

Create 2 EC2 instances for the master and agent

Generate SSH key on the jenkins-server using “ssh-keygen” command.

ssh-keygen

Now go to that folder and copy the id_rsa.pub which is public key.

Then on the jenkins-agent-1, paste the public key from the jenkins-server in the authorized_keys file.

 cd .ssh
 ls
 vi authorized_keys

Now from the jenkins-server we can connect the jenkins-agent-1 server

 # inside ssh dir
 ssh ubuntu@<Public-IPv4-addr>

 # if we exit we will be back to jenkins-server.

Create an agent by setting up a node on Jenkins

Give Node name and click on Permanent Agent and click on Create.

create and Add details of your node, accordingly.

Now click “OK” and Node will be connected and online.

Set Up Node Application

Now create a new item with the pipeline, and named it(node-pipeline)

In pipe line section we assign task to Agent and provide grovey Command

After this save it and build it after the build success check it with your agent node

Showing project.

Again rewrite the Grovy command to build and run. Save it and build it.

Thanks for reading this article!!