Created
October 11, 2022 05:07
-
-
Save xiaojueguan/1fc75311f29838d9733590b2b42ade2d to your computer and use it in GitHub Desktop.
script snippt to get slaves from jenkins to json format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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