Skip to content

Instantly share code, notes, and snippets.

@allyunion
Created October 29, 2018 23:06
Show Gist options
  • Save allyunion/09a9af4ce75772f97b6adf5736d4b87a to your computer and use it in GitHub Desktop.
Save allyunion/09a9af4ce75772f97b6adf5736d4b87a to your computer and use it in GitHub Desktop.
Add a Jenkins Slave node
SLAVE_NAME=$1
CREDENTIALS_ID=<INSERT_CREDENTIALS_HERE>
# USERNAME & PASSWORD is read from Jenkins credentials
cat <<EOF | java -jar /var/lib/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/ create-node ${SLAVE_NAME} --username $USERNAME --password $PASSWORD
<slave>
<name>${SLAVE_NAME}</name>
<description>A Jenkins Slave node</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>${SLAVE_NAME}.example.com</host>
<port>22</port>
<credentialsId>${CREDENTIALS_ID}</credentialsId>
<maxNumRetries>0</maxNumRetries>
<retryWaitTime>60</retryWaitTime>
</launcher>
<label>slave</label>
<nodeProperties/>
<userId>${USERNAME}</userId>
</slave>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment