Wed. Oct 4th, 2023

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
  <name>Slave 1</name>
  <retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
  <launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.10">

Things to change:



nameThis is the slave name, each slave must have a unique name.
hostThe hostname or IP address to the slave.
credentialsIdThe credentials ID to login on this Slave.  This can be found in the URL by opening up the Credentials that correspond to this slave.

By Jeffery Miller

I am known for being able to quickly decipher difficult problems to assist development teams in producing a solution. I have been called upon to be the Team Lead for multiple large-scale projects. I have a keen interest in learning new technologies, always ready for a new challenge.

2 thoughts on “Jenkins Add Slave via Command LIne”
  1. 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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: