How to add slave host in Jenkins?

Quick and dirty guide to add a slave host to running in Docker on Linux-based machines.

The registering of a slave host in requires several steps.

1. Login to a slave host via SSH from the master host

At first you need to login to the container with Jenkins: docker exec -it <hash> bash. From the container you need to login via SSH to the host which you want to add. During this operation it automatically will add SSH footprint.

2. Add a node in UI

Go to Manage Jenkins --> Manage Nodes --> New Node. In the configuration you need to specify the following settings:

  • Name – this will be a node label in your Jenkinsfile if you use it
  • Remote root directory – I’m using /jenkins_slave, this folder should be created on the slave host
  • Launch method – set Launch agents via SSH and specify Host and SSH credentials. I’m also set Host Key Verification Strategy to Non verifying Verification Strategy (don’t remember why).

3. Activate the agent from web UI

You need to go to this agent from the list and press Relaunch agent

You will see some logs and depends on errors messages you may need to do additional configuration. If it says about Java version install JDK sudo apt install default-jdk. If it says something about SSH error you may need to generate it. Run ssh-keygen on the slave.

4. Apply correct permissions to folder jenkins_slave

Above I mentioned that a folder should be specified in Remote root directory setting of the new node. I’m using jenkins_slave. The owner of this folder should be the same user as Jenkins login in via SSH. Use the command chown jenkins jenkins_folder.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Post

%d bloggers like this: