Skip to content

Instantly share code, notes, and snippets.

@xiaojueguan
Created October 11, 2022 05:07
Show Gist options
  • Save xiaojueguan/1fc75311f29838d9733590b2b42ade2d to your computer and use it in GitHub Desktop.
Save xiaojueguan/1fc75311f29838d9733590b2b42ade2d to your computer and use it in GitHub Desktop.
script snippt to get slaves from jenkins to json format
import hudson.model.Hudson.instance.slaves
import groovy.json.JsonOutput
def getSlaves() {
slaves = []
hudson.model.Hudson.instance.slaves.each{val->
slave = [:]
slave['name'] = val.getNodeName()
slave['home_dir'] = val.getRemoteFS()
launcher = val.getLauncher()
slave['host'] = launcher.getHost()
// not cloudbees ssh plugin
// slave['port'] = launcher.getPort()
// slave['credential'] = launcher.getCredentialsId()
slave['credential'] = 'linux-root'
slave['port'] = 22
slave['nodeDescription'] = val.getNodeDescription()
slave['numExecutors'] = val.getNumExecutors()
slave['labelString'] = val.getLabelString()
slave['mode'] = val.getMode().getName()
// temparrly we undocumented here
// slave['retentionStrategy'] = val.getRetentionStrategy()
slaves.add(slave)
}
return JsonOutput.toJson(slaves)
}
print(getSlaves())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment