Adding new Jenkins Node(Agent)
Logesh Sakthivel
Posted on May 29, 2023
The Jenkins architecture is designed for distributed build environments. It allows us to use different environments for each build project balancing the workload among multiple agents running jobs in parallel.
The Jenkins controller is the original node in the Jenkins installation - jenkins.io
To build Jobs on the remote machine by Jenkins we need to add that machine as a Node(Agent) to our Jenkins Controller.
The agents require a Java installation and a network connection to the Jenkins controller.
In this article we are going to learn how to add an Ubuntu machine as an agent to the Jenkins controller.
I have installed Jenkins controller in my Windows machine. Ubuntu is installed on VMware Workstation (by Virtualization).
Prerequisite to add my Ubuntu machine as a Jenkins Agent
- Network connection between the machine and the Jenkins controller
- Java installed on the machine (Agent)
Adding new Node
In the Jenkins Dashboard, Manage Jenkins -> Manage nodes and clouds. Now you are in the Nodes page.
You can directly jump to this page from the Dashboard by clicking the Build Executor Status in the bottom left corner.
New Node
Okay. Now we are going to add node by clicking New Node.
Number of executors - this should be less than or equal to number CPUs or vCPUs of that machine.
Remote root directory - An agent needs to have a directory dedicated to Jenkins. Specify the path to this directory on the agent. It is best to use an absolute path, such as /var/jenkins or c:\jenkins. This should be a path local to the agent machine. - from the help menu
Labels - Labels (or tags) are used to group multiple agents into one logical group.For example, if you have multiple Windows agents and you have a job that must run on Windows, then you could configure all your Windows agents to have the label windows, and then tie that job to this label.
This would ensure that your job runs on one of your agents, but not on any agents without this label.Multiple labels must be separated by a space.
- Usage - Controls how Jenkins schedules builds on this node. Two available options
Use this node as much as possible. This option makes Jenkins to use this Node whenever possible. Ex: If a Job is triggered with the label "any "then the node which uses this option will aslo build that Job.
Only build jobs with label expressions matching this node
This allows Jenkins to build the Job on this node that exactly matches the Label of this node.
- Launch method - This has 3 options.
- Launch agent by connecting it to the controller
- Launch agent via execution of command on the controller
- Launch agents via SSH
I will be using the 3rd option. For this SSH service needs to be enabled on the Ubuntu machine.
To enable SSH on Ubuntu checkout my article here.
For the Launch method I have used SSH. That asks
Host- hostname or IP of the machine
Credentials- Login creds (username/password)
Host Key Verification Strategy - since we are using SSH this asks how to verify the remote host key. I have used Manually trusted key Verification Strategy option. For this either we need to manually first verify the remote key before launching the Node else it will automatically verify at the time of launching. If we check this Require manual verification of initial connection checkbox then we must manually first verify the host key by manually connecting to it.
You can also explore the other "Host Key Verification Strategy"
- Availability - this decides when to start and stop the Agent.
I have choosed "Keep this agent online as much as possible".
Save the details.
In the Nodes page we could see our machine added as a Node
Select our Node.
Check the connection log by clicking the Log tab.
In the above log we could see that the SSH key has been automatically trusted for connections to this machine because I haven't verified manually.
In the above image we could see that Jenkins Controller created the directory (we specified while adding the node) for the files related to Jenkins operations in the Node.
Ubuntu machine is now added as an Jenkins Node (Agent).
Happie Learning :)
Keep Learning!!!
Posted on May 29, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024