Last active
February 8, 2016 20:25
-
-
Save apemberton/a3ac2e6d9f504baca08f to your computer and use it in GitHub Desktop.
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 com.cloudbees.opscenter.server.model.*; | |
import com.cloudbees.opscenter.server.clusterops.steps.*; | |
import hudson.remoting.*; | |
def cjoc = getHost(new LocalChannel()) | |
cjoc.masters = [] | |
Jenkins.instance.getAllItems(ConnectedMaster.class).each { | |
cjoc.masters.add(getHost(it.channel)) | |
} | |
def getHost(channel){ | |
def host | |
if(channel){ | |
def stream = new ByteArrayOutputStream(); | |
def listener = new StreamBuildListener(stream); | |
channel.call(new MasterGroovyClusterOpStep.Script(""" | |
def host = [url:Jenkins.instance.rootUrl] | |
return new groovy.json.JsonBuilder(host).toString() | |
""", listener, "host-script.groovy")); | |
host = new groovy.json.JsonSlurper().parseText(stream.toString().minus("Result: ")); | |
} else { | |
host = [type:type, name:name, offline:true] | |
} | |
return host; | |
} | |
return new groovy.json.JsonBuilder(cjoc).toPrettyString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment