I'd like to connect a build node to the Jenkins master. Ideally without using a web browser or being in front of the physical machine. What would be the easiest way to achieve that?
1 Answer
Connecting a node to Jenkins through a terminal only is a two step process.
First, you should ssh into into your node machines and set them up with the following steps:
Make a jenkins user shell:
sudo adduser jenkins --shell /bin/bash
Create the directory after switching to the jenkins user:
mkdir /home/jenkins/jenkins_slave
Create your SSH credentials to be used in the following bash script.
Then, once your nodes are set up, you will need to connect to your jenkins machine and run bash script such as this one to connect your nodes to your master:
#!/bin/bash
JENKINS_URL=$1
NODE_NAME=$2
NODE_SLAVE_HOME='/home/build/slave'
EXECUTORS=1
SSH_PORT=22
CRED_ID=$3
LABELS=build
USERID=${USER}
cat <<EOF | java -jar ~/bin/jenkins-cli.jar -s $1 create-node $2
<slave>
<name>${NODE_NAME}</name>
<description></description>
<remoteFS>${NODE_SLAVE_HOME}</remoteFS>
<numExecutors>${EXECUTORS}</numExecutors>
<mode>NORMAL</mode>
<retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
<launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="[email protected]">
<host>${NODE_NAME}</host>
<port>${SSH_PORT}</port>
<credentialsId>${CRED_ID}</credentialsId>
</launcher>
<label>${LABELS}</label>
<nodeProperties/>
<userId>${USERID}</userId>
</slave>
EOF
-
1It should be noted that this does not really require connecting with SSH to the node, since you can run the CLI call remotely. Commented Mar 2, 2017 at 5:16