Created
February 25, 2012 06:53
-
-
Save kellyrob99/1907119 to your computer and use it in GitHub Desktop.
Samples of running Groovy scripts remotely on the Jenkins/Hudson server through the CLI
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
@GrabResolver(name='glassfish', root='http://maven.glassfish.org/content/groups/public/') | |
@GrabResolver(name="github", root="http://kellyrob99.github.com/Jenkins-api-tour/repository") | |
@Grab('org.kar:hudson-api:0.2-SNAPSHOT') | |
@GrabExclude('org.codehaus.groovy:groovy') | |
import org.kar.hudson.api.cli.HudsonCliApi | |
String rootUrl = 'http://localhost:8080' | |
HudsonCliApi cliApi = new HudsonCliApi() | |
def listPlugins = 'Hudson.instance.pluginManager.plugins.each { \ | |
println("${it.longName} - ${it.version}") };' | |
def allFailedBuilds = '''hudsonInstance = Hudson.instance | |
allItems = hudsonInstance.items | |
activeJobs = allItems.findAll{job -> job.isBuildable()} | |
failedRuns = activeJobs.findAll{job -> job.lastBuild && job.lastBuild.result == Result.FAILURE} | |
failedRuns.each{run -> println(run.name)}''' | |
def parseableAllFailedBuilds = '''hudsonInstance = Hudson.instance | |
allItems = hudsonInstance.items | |
activeJobs = allItems.findAll{job -> job.isBuildable()} | |
failedRuns = activeJobs.findAll{job -> job.lastBuild && job.lastBuild.result == Result.FAILURE} | |
[activeJobs:activeJobs?.collect{it.name}, failedRuns:failedRuns?.collect{it.name}].inspect()''' | |
[listPlugins, allFailedBuilds, parseableAllFailedBuilds].each{ script -> | |
cliApi.runCliCommand(rootUrl, ['groovysh', script]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment