Skip to content

Instantly share code, notes, and snippets.

@apemberton
Created February 10, 2016 14:19
Show Gist options
  • Save apemberton/047b08bb8a5c63402364 to your computer and use it in GitHub Desktop.
Save apemberton/047b08bb8a5c63402364 to your computer and use it in GitHub Desktop.
//master, regular slaves, and shared slaves
def nodes = []
(Jenkins.instance.computers.grep {
it.class.superclass?.simpleName != 'AbstractCloudComputer' &&
it.class.superclass?.simpleName != 'AbstractCloudSlave' &&
it.class.simpleName != 'EC2AbstractSlave'
}
).each {
nodes.add([type:it.class.simpleName, name:it.displayName, executors:it.numExecutors])
}
//clouds
def clouds = []
Jenkins.instance.clouds.each {
def cloud = [type:it.descriptor.displayName, name:it.displayName]
try{
cloud.executorsCap = it.templates?.inject(0, {a, c -> a + (c.numExecutors * c.instanceCap)})
}catch(e){}
try{
cloud.executorsPerNode = it.numExecutors
}catch(e){}
clouds.add(cloud)
}
def host = [type:'Master', name:'Master', url:Jenkins.instance.rootUrl, cores:Runtime.runtime.availableProcessors(), nodes:nodes, clouds:clouds, offline:false]
return new groovy.json.JsonBuilder(host).toPrettyString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment