Open In App

Difference Between Jenkins Agent And Node

Last Updated : 11 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Jenkins is a popular open-source tool to perform continuous integration and build automation. Jenkins has established itself as a go-to tool for automating the development process. Jenkins can distribute tasks across multiple machines or environments, which are often referred to as agents or nodes. While we sometimes use these terms interchangeably, they serve distinct purposes in the Jenkins ecosystem. In this article, we will be exploring the differences between Jenkins Agent and Node.

Jenkins Agent

A Jenkins agent, also referred to as a Jenkins slave, is a worker machine, or container, that connects to a Jenkins controller and executes tasks when directed by the controller. The agent section specifies where the entire pipeline or specific stage will execute in the Jenkins environment, depending on where the agent is placed. Agents are used to offload tasks from the Jenkins master; this makes possible parallel execution of jobs and scalability of the Jenkins infrastructure.

Example: You can think of Jenkins agents as specialized workers in a factory. In the factory, there is a control room (Jenkins Master) where production schedules are managed. When there is a need to assemble a product( run a building job), the control room assigns tasks to workers (agents) who may be working in different locations. Each worker executes their tasks independently, which allows multiple products to be assembled simultaneously.

Jenkins Node

A Jenkins node, also known as a Jenkins server, is any machine (physical or virtual) connected to the Jenkins network or the Jenkins environment. Node is capable of executing pipelines or jobs. Nodes provide computational resources and environments to execute Jenkins build jobs. Both controllers and agents are considered to be nodes.

Example: Imagine a network of offices in a company where every office has several employees to perform tasks. Similarly, in Jenkins, each office represents a node, and each node represents a machine that contributes resources to execute Jenkins tasks. As each department in an office has unique tools and expertise, each node can have its own set of tools and resources.

Differences between Jenkins Agent and Node

Aspect

Jenkins Agent

Jenkins Node

Definition

Jenkins Agent are the worker machines that execute tasks as directed by the Jenkins controller.

Jenkins Nodes are any machine ( be it physical or virtual) connected to the Jenkins environment and capable of executing pipelines or jobs.

Purpose

Agents executes Jenkins tasks remotely.

Nodes provide resources to execute Jenkins tasks.

Relationship to Master

Operates under the control of the Jenkins master.

Includes Jenkins master and any agents.

Configuration

Configured as separate entities from the Jenkins master.

Includes both master and connected agents.

Scalability

More agents can be added if required.

Scales as the Jenkins environment grows.

Resource Utilization

Resources can be optimized for specified tasks.

Node utilizes resources available on the machine.

Management

Agents are managed by Jenkins master or controller

Nodes may have dedicated management systems or scripts.

Network Connectivity

May require VPN or firewall rules for external agents.

Requires network connectivity within the Jenkins network.

Set Up Jenkins-Agent& Jenkins-Node

Step 1: In the Jenkins Dashboard, go to the “Manage Jenkins” option displayed on the left sidebar.

Manage Jenkins

Step 2: Click on the Nodes under System Configuration.

Nodes

Step 3: Now click on “New Node” and give a name to the Jenkins Node and select Type as “Permanent Node”. Then click on “Create”.

Add Node

Step 4: Configure the Node settings, specify the path for remote root directory which in this case we are giving as “/home/jenkins” and use a Label for further use which here we are giving as “agent1”. Leave others field as default. Now click on “Save”.

Root Directory

Once done, we can see our Node in the Nodes section.

Node

Step 5: Now to make it connected, Click on the Agent name and copy the code from “Run from agent command line”

Run from agent command line

and run it on terminal or command prompt from the Remote root directory of the remote machine’s terminal. Now, you will be able to see Agent is connected.

Agent added

Set Up Node Application

Step 1: First thing we need to do is setup the NodeJS plugin in the Jenkins. Go to manage Jenkins and then to the Plugins section. In the available plugins section search for NodeJs
Plugins

Tick the box below and then install. Once done restart Jenkins.

Step 2: Go to Manage Jenkins and then to Tools and scroll down to NodeJS area.

NodeJS

Select “Add NodeJS” and Name it as you want and select the latest version of NodeJS available.

NodeJS version

Now click on “Save”.

Using Pipeline Script

Step 3: Once you have completed the first two steps of the previous section. You can go ahead and create a New Item.

New Item

Step 4: Name it as you want and select pipeline from the options given below and click on save.

Pipeline

Step 5: On the next screen, scroll down to the pipeline section and write your script for the node application.

Pipeline Script

Here, we are giving your NodeJS version and then using npm version to validate it.

pipeline{
agent any
tools{
nodejs '21.6.2'
}
stages{
stage('Example'){
steps{
sh 'npm version'
}
}
}
}

Click on Save.

Step 6: Click on the Build Now button showing on the left sidebar.

Build

Step 7: Now go to console and you should be able to see the Node version

Console

Scroll down to see the build successful message.

Build Success

Conclusion

Jenkins agents and nodes play crucial roles within the Jenkins ecosystem. These enables an efficient and scalable automation build and deployment processes. Agents serve as worker machines and executes Jenkins build tasks while Node provides the computational resources for agents to perform tasks. As Software Development practices continue to evolve, the role of Jenkins agents and nodes remains important in context of seamless automation in Software development life cycle.

Difference between Jenkins Agent and Node – FAQ’s

Why Jenkins agents are required?

Jenkins agents executes Jenkins build tasks assigned by controller, which helps in parallel execution of jobs.

Can Jenkins master function as an agent?

Yes, It is possible for a Jenkins master to perform as an agent. But it is not recommended due to potential performance and security issues. It is always a good practice to have separate machines or environments as agents.

What is Jenkins Node?

Jenkins nodes are the physical or virtual machines that provide resources to the Jenkins agents to perform task. In short, we can say that Jenkins Nodes are the machines on which agents run.

What are the different types of Jenkins Nodes?

There are two types of Jenkins Nodes, one is Permanent Nodes which typically represents dedicated machines, another one is Ephemeral nodes represents short-lived environments in Cloud.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads