Skip to content

Instantly share code, notes, and snippets.

View kellyrob99's full-sized avatar

Kelly Robinson kellyrob99

View GitHub Profile
@kellyrob99
kellyrob99 / graphGenerator.groovy
Created April 23, 2012 01:57
Given a GraphViz dot file, create combinations of layouts and output formats; depends on having the dot executable preinstalled
import groovyx.gpars.GParsPool
def inputfile = args[0]
def layouts = [ 'twopi', 'sfdp', 'osage']
def formats = [ 'pdf','svg']
def combinations = [layouts, formats].combinations()
GParsPool.withPool(4) {
combinations.eachParallel { combination ->
String layout = combination[0]
@kellyrob99
kellyrob99 / repos.groovy
Created April 23, 2012 01:25
Access the Github V3 api and find all watchers for a specified user's repositories. Generates output suitable for processing by https://gist.github.com/2475460
@Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.5.2')
import groovy.json.JsonBuilder
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.JSON
final rootUser = args[0]
final String RATE_LIMIT_HEADER = 'X-RateLimit-Remaining'
final String rootUrl = 'https://api.github.com'
final Closure<Boolean> hasWatchers = {it.watchers > 1}
final Closure findReposForUser = { HTTPBuilder http, username ->
@kellyrob99
kellyrob99 / jenkinsGroovyShell.groovy
Created February 26, 2012 01:09
Launch an interactive Groovy shell to a Jenkins server
@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
/**
* Open an interactive Groovy shell that imports the hudson.model.* classes and exposes
* a 'hudson' and/or 'jenkins' object in the Binding which is an instance of hudson.model.Hudson
*/
HudsonCliApi cliApi = new HudsonCliApi()
@kellyrob99
kellyrob99 / findAndTriggerFailedBuilds.groovy
Created February 26, 2012 00:44
Find and trigger all failed builds on a machine
@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()
OutputStream out = new ByteArrayOutputStream()
def script = '''hudson.items.findAll{ job ->
@kellyrob99
kellyrob99 / nameAllJobs.groovy
Created February 25, 2012 19:53
Call Jenkins CLI and return the names of all Jobs
@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()
OutputStream out = new ByteArrayOutputStream()
cliApi.runCliCommand(rootUrl, ['groovysh', 'hudson.jobNames.inspect()'], System.in, out, System.err)
@kellyrob99
kellyrob99 / examineJenkinsCommands.groovy
Created February 25, 2012 18:18
Call Jenkins CLI command with no arguments to elicit the required arguments for each.
@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 static java.net.HttpURLConnection.*
import org.kar.hudson.api.*
import org.kar.hudson.api.cli.HudsonCliApi
String rootUrl = 'http://localhost:8080'
HudsonCliApi cliApi = new HudsonCliApi()
@kellyrob99
kellyrob99 / setupNewServer.groovy
Last active June 21, 2021 13:24
Install a suite of plugins in a locally running Jenkins/Hudson server and restart it.`
@GrabResolver(name='glassfish', root='http://maven.glassfish.org/content/groups/public/')
@GrabResolver(name='jenkins', root='http://maven.jenkins-ci.org/content/repositories/releases')
@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 static java.net.HttpURLConnection.*
import org.kar.hudson.api.*
import org.kar.hudson.api.cli.HudsonCliApi
String rootUrl = 'http://localhost:8080'
@kellyrob99
kellyrob99 / cliGroovyshSamples.groovy
Created February 25, 2012 06:53
Samples of running Groovy scripts remotely on the Jenkins/Hudson server through the CLI
@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 { \
@kellyrob99
kellyrob99 / updateAllPlugins.groovy
Created February 25, 2012 06:51
Jenkins/Hudson recipe for updating all Plugins using the CLI
def findPluginsWithUpdates = '''
Hudson.instance.pluginManager.plugins.inject([]) { List toUpdate, plugin ->
if(plugin.hasUpdate())
{
toUpdate << plugin.shortName
}
toUpdate
}.inspect()
'''
OutputStream updateablePlugins = new ByteArrayOutputStream()
@kellyrob99
kellyrob99 / grettyGreenMailServer.groovy
Created December 28, 2011 02:06
Use Gretty to provide a JSON front end for a GreenMail smtp test server
@GrabResolver(name = 'gretty', root = 'http://groovypp.artifactoryonline.com/groovypp/libs-releases-local')
@Grab('org.mbte.groovypp:gretty:0.4.279')
@Grab('com.icegreen:greenmail:1.3.1b')
import javax.mail.internet.MimeMessage
import org.jboss.netty.channel.local.LocalAddress
import org.mbte.gretty.httpserver.GrettyServer
import com.icegreen.greenmail.user.*
import com.icegreen.greenmail.util.*
//create the greenmail server