The registering of a slave host in Jenkins 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 Jenkins UI
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 SSHand specify Host and SSH credentials. I’m also set
Host Key Verification Strategyto
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
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
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.