Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stewartbryson/e94a10fc450d3ca34b23 to your computer and use it in GitHub Desktop.
Save stewartbryson/e94a10fc450d3ca34b23 to your computer and use it in GitHub Desktop.
/*
* Tis ugly, but you can get the gist from this
*/
println "Getting past test status from Jenkins"
/* Depth */
depth = 2
/* Project Name */
projectName = "junit-and-tap"
jenkins = hudson.model.Hudson.instance
project = jenkins.getItem(projectName)
runs = project.getBuilds()
// dirty :/ blergh
map = new java.util.HashMap()
builds = new java.util.LinkedList()
class HistoryResult {
def buildNumber
def status
}
index = 1
for(run in runs) {
if(index > depth)
break
builds.add(run.getNumber())
testActions = run.getActions(hudson.tasks.test.AbstractTestResultAction.class);
for(hudson.tasks.test.AbstractTestResultAction testAction in testActions) {
result = testAction.getResult()
children = result.getChildren()
for(child in children) { // packageresult
if(child instanceof hudson.tasks.junit.PackageResult) {
for(child2 in child.getChildren()) { // classresult
for(child3 in child2.getChildren()) { // caseresult
key = child.name + "." + child2.name + "#" + child3.name
value = null
if(map.get(key) != null) {
value = map.get(key)
} else {
value = new java.util.HashMap()
}
historyResult = new HistoryResult()
historyResult.buildNumber = run.number
historyResult.status = child3.status
value.put(run.number, historyResult)
map.put(key, value)
}
}
}
}
}
index++
}
// print le table!
print "Test / Build\t\t"
for(build in builds) {
print "" + build + "\t"
}
println ""
for(testName in map.keySet()) {
print "" + testName + "\t"
for(build in builds) {
print "" + map.get(testName).get(build).status + "\t"
}
println ""
}
println "OK! Done"
/*
kinow@chuva:~/Desktop$ java -jar jenkins-cli.jar -s http://localhost:8080 groovy = < get_past_test_status.groovy
Getting past test status from Jenkins
Test / Build 4 3
net.cars.engine.MoteurTest#selfTest PASSED PASSED
net.cars.engine.MoteurTest#hasCarburatueur PASSED PASSED
net.cars.engine.MoteurTest#hasBougie PASSED PASSED
net.cars.engine.MoteurTest#hasPiston PASSED PASSED
net.cars.engine.MoteurTest#hasDemareur PASSED PASSED
net.cars.engine.MoteurTest#hasDelco PASSED PASSED
OK! Done
kinow@chuva:~/Desktop$
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment