Skip to content

Instantly share code, notes, and snippets.

@kinow
Created October 17, 2012 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kinow/3906161 to your computer and use it in GitHub Desktop.
Save kinow/3906161 to your computer and use it in GitHub Desktop.
get_past_test_status.groovy
/*
* 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