Adding new Jenkins Node(Agent)
Tags: jenkins
Published: 2023-05-29 14:31:53

_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.


![Jenkins Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ea29063cwx7n9374ibl9.png)


![Manage Jenkins](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxn6jazr70xm8nfy8o01.png)



![Manage nodes and clouds](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grvynctmw8qqc6bfmjtq.png)


You can directly jump to this page from the Dashboard by clicking the Build Executor Status in the bottom left corner.


![Build Executor Status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vojhi3bp020uzsaynmhu.png)

## New Node

Okay. Now we are going to add node by clicking New Node.


![New Node](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yyaib4bakjfrea1lq6rk.png)


![create new node](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hslku9rtd8xs8wnw01pi.png)


![add details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w807g0n3lthqm5lu4uc0.png)

- **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.


![My info](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l9no54qqb1pt37to7fr.png)


![Usage, Launch method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0v1bcdx5d6bgqmg4hx1b.png)


- **Usage **- Controls how Jenkins schedules builds on this node. Two available options

1. 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.

2. 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.

1. Launch agent by connecting it to the controller
2. Launch agent via execution of command on the controller
3. 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](https://medium.com/@LogeshSakthivel/enable-ssh-on-ubuntu-708d20071a2e).

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,Node Properties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2tknpa08y9ntnc5ezhei.png)

- **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

![Nodes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q245j6jf3ibutpl6s29l.png)


Select our Node.

![Our Node](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8iy88xxeq2qjgteabikq.png)


Check the connection log by clicking the Log tab.


![SSH connection log(automatically trusted)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mniuw5mzf9981n54oxgx.png)

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.

![jenkins dir in our Ubuntu machine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awh12q19m6opzt2csr8r.png)


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!!!