In this guide we will explore how to add slaves (build nodes) to jenkins.
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. These build environments are what were refer to as the slaves.
The Jenkins controller is the orignal node in the Jenkins installation. The Jenkins controller administers the Jenkins agents and orchestrates their work, including scheduling jobs on agents and monitoring agents. Agents may be connected to the Jenkins controller using either local or cloud computers.
The agents require a Java installation and a network connection to the Jenkins controller.
To add jenkins slave, you need the following:
- Jenkins server
- At least one other server to use as slave
On the slave server, ensure java is installed:
Install java on your system. We will be using the openjdk version of java. In centos 8, to check what software provides the java command line, use the following command:
dnf whatprovides java
# dnf whatprovides java Last metadata expiration check: 0:05:13 ago on Wed 13 Jan 2021 08:12:25 AM UTC. java-1.8.0-openjdk-1:188.8.131.525.b01-1.el8_3.x86_64 : OpenJDK Runtime Environment 8 Repo : AppStream Matched from: Provide : java = 1:1.8.0
We can see that it is provided by the
java-1.8.0-openjdk-1:184.108.40.2065.b01-1.el8_3.x86_64. Install it using the command
dnf install java-1.8.0-openjdk-1:220.127.116.115.b01-1.el8_3.x86_64
After the installation is complete, check the installed java version.
Add New User
Now we need to add a user that the jenkins master will use to connect to the slaves. We will create a user called
Run the command below.
useradd -m -s /bin/bash jenkins passwd jenkins
Generate ssh key to use
Use this command to generate ssh key
ssh-keygen -t rsa -b 4096 -f ~/.ssh/jenkins_key
Copy the SSH Key to use
Upload the key generated to the slave.
ssh-copy-id -i ~/.ssh/jenkins_key [email protected]
Add New Slave Nodes
- On the Master Jenkins dashboard, click the ‘Manage Jenkins’ menu, and click ‘Manage Nodes And Clouds’.
- Click the ‘New Node’.
- Type the node name ‘slave01’, choose the ‘permanent agent’, and click ‘OK’.
- Now type node information details.
- Description: slave01 node agent server
- Remote root directory: /home/jenkins/slave01
- Labels: slave01
- Launch method: Launch slave agent via SSH, type the host ip address ‘10.0.15.21’, choose the authentication using ‘Jenkins’ credential.
- Now click ‘Save’ button and wait for the master server to connect to all agent nodes and launch the agent services.
To test this, create a job and on the ‘Label Expression’, specify the node such as ‘slave01’. Run the job.