Overview
Jenkins provides a cli that can used for remote adminstration, which comes bundled with each installation. In this post we will learn how to remotely add new slaves with the tool.
Node Credentials
All master-node communications are handled through SSH over port 22. A username and RSA key-pair is used by the Master node to manage the remote node, which must be created in the Jenkins credential store.
- Log into the Jenkins master node with a user that has administrative privileges.
- From the navigation sidebar, navigate to Credentials > System > Global Credentials
- Click Add Credentials from the sidebar
- From the Kind drop menu, select SSH Username with private key
- In the ID field, enter jenkins as the ID. The ID is used to reference the credential in pipelines and operational tasks, such as adding new nodes.
- Provide a description of the credential in the Description field.
- In the Username field, enter jenkins
- For the private key, select Enter directly, and paste the contents of the private key we created earlier.
- If your key-pair is secured using a passphrase, enter it in the passphrase field.
Preparing the Node
In order to register a new Jenkins slave remotely you will need to perform a few tasks.
- Create a new user with name that matches the Jenkins Credential username created earlier. The user must have a home directory set and use the Bash shell as its default shell.
- Create the SSH directory for your Jenkins user.
- Create a file named authorized_keys in the SSH directory.
- Add the contents of the public key of the RSA key-pair created in the Getting Started section above.
- Set the permissions of the SSH directory and all of its files so as to only allow the Jenkins user read access.