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?
Asked
Active
Viewed 2,804 times
1 Answers
3
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/bashCreate the directory after switching to the jenkins user:
mkdir /home/jenkins/jenkins_slaveCreate 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="ssh-slaves@1.5">
<host>${NODE_NAME}</host>
<port>${SSH_PORT}</port>
<credentialsId>${CRED_ID}</credentialsId>
</launcher>
<label>${LABELS}</label>
<nodeProperties/>
<userId>${USERID}</userId>
</slave>
EOF
avi
- 1,279
- 1
- 13
- 32