This is a post I have been thinking about writing for some time and I finally had the time to do that.
In the beginning, it could be enough to use just a single Jenkins instance (master), but sooner or later as the team grows up and the number of pipelines running concurrently increases, you will feel the need to power up your CI/CD pipeline. One of the things you can do is to add Jenkins slaves. I have read many procedures about adding Jenkins slaves on Linux machines but none worked for me. I have created my own guide on how to add a slave Jenkins node working on Linux (namely Centos7). Below are the steps:
Upload slave.jar to the slave node. Jenkins provides a link for you to download this jar.
Write a script on the Jenkins master to launch this slave.jar on the slave (replace the IP with your slave’s)
ssh 192.168.63.121 java -jar /usr/bin/slave.jar
Create ssh key pair on Jenkins master using “keygen”
Copy the public key to the trusted keys of the slave using “ssh-copy-id” command (ssh-copy-id [email protected])
On Jenkins master create a global credential (unrestricted) with a user’s credential that can ssh to the slave machine
Follow the steps in Jenkins UI to add a New Node:
Create a directory in the salve and add it as “remote root directory” in the setting screen
Usage -> use this node as much as possible
Launch method -> launch slave agents via ssh
Add ip of the slave for the HOST value
Select the credentials you have previously created
“Host key verification strategy” -> Manually trusted key verification strategy
Don’t check the box saying “require manual verification of initial connection”
Availability -> keep this agent online as much as possible
SAVE the settings.
Depending on the tasks/commands you want to be run on the Jenkins slave nodes may need to install a couple of software tools on it:
If you are running OpenShift commands on your pipeline scripts as I do, you need to install OpenShift client tools. Also, set the server URL for the OpenShift cluster. This is the URL at which OpenShift Container Platform admin console is launched (Ex: https://tybsrhosmaster01.defence.local:8443). There are 2 ways to set this URL;
1-) Remote login or ssh to the Jenkins server, launch a terminal, “run oc login”, enter the URL.
2-) Edit “config” file under .kube folder manually.
If you are using a build manager for your java apps don’t forget to install that. In my case it is Maven. After installing that, you may also need to copy some config files from the master like settings.xml under .m2 folder.
If you are building java apps don’t forget to install JDK, configure JAVA_HOME and add it to PATH
If you encounter an error similar to the one below, try creating “/var/lib/jenkins/.ssh/known_hosts” and add the IP of the slave into this file.
[06/12/18 15:55:36] [SSH] Opening SSH connection to 192.168.63.121:22.
/var/lib/jenkins/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/lib/jenkins/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
java.io.IOException: There was a problem while connecting to 192.168.63.121:22
Caused by: java.io.IOException: Key exchange was not finished, connection is closed.
… 9 more
Caused by: java.io.IOException: The server hostkey was not accepted by the verifier callback
… 1 more
[06/12/18 15:55:51] Launch failed – cleaning up connection
[06/12/18 15:55:51] [SSH] Connection closed.
Hope this helps.