Sometimes you need to be able to add a slave to Jenkins Master via the command line. I have taken great use of that recently by having it automatically add Docker Slaves. Here is the code:
cat <<EOF | java -jar jenkins-cli.jar -s http://localhost:8080/ create-node Slave1 --username $username --password $password
<slave>
<name>Slave 1</name>
<description></description>
<remoteFS>/home/jenkins</remoteFS>
<numExecutors>5</numExecutors>
<mode>NORMAL</mode>
<retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
<launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.10">
<host>192.168.0.124</host>
<port>22</port>
<credentialsId>93aa6353-0b12-48d9-8533-6a3dc1b02b83</credentialsId>
<maxNumRetries>0</maxNumRetries>
<retryWaitTime>0</retryWaitTime>
</launcher>
<label>slave</label>
<nodeProperties/>
<userId>jeff@mymiller.name</userId>
</slave>
EOF
Things to change:
Setting |
Description |
name | This is the slave name, each slave must have a unique name. |
host | The hostname or IP address to the slave. |
credentialsId | The credentials ID to login on this Slave. This can be found in the URL by opening up the Credentials that correspond to this slave. |
java -jar jenkins-cli.jar -s http://localhost:8080/ get-node Slave1 –username $username –password $password
Hi Jeff, thanks for this post. I have a question, is there a command to fetch the configuration details of an existing slave , like the config mentioned above? I want to add an aws instance,and i need to send various parameters like keys, access key etc