Skip to content

Instantly share code, notes, and snippets.

@Lenbok
Created July 8, 2014 22:59
Show Gist options
  • Save Lenbok/7bfaf2ba590c05acfef3 to your computer and use it in GitHub Desktop.
Save Lenbok/7bfaf2ba590c05acfef3 to your computer and use it in GitHub Desktop.
Traffic-light / tinderbox style indicator columns in jenkins build history table
// Requires the groovy postbuild plugin. Supports several types of checkers
// Set debug to true if running in the jenkins groovy script console for testing, and update job name in the getJob call
// Set debug to false when added as groovy postbuild action
def debug = false
def job = debug ? Jenkins.getInstance().getJob("genopipe") : null
def build = debug ? job.getLastBuild() : manager.build
build.actions.each { action ->
if (debug) {
println(action.class.simpleName)
}
if ((action.class.simpleName == "CheckStyleResultAction")
|| (action.class.simpleName == "FindBugsResultAction")
|| (action.class.simpleName == "WarningsResultAction")) {
def high = action.result.getAnnotations("HIGH").size()
def norm = action.result.getAnnotations("NORMAL").size()
def low = action.result.getAnnotations("LOW").size()
def label = action.result.getNumberOfWarnings() + " " + action.displayName
badge = "error.gif"
if (high > 0) {
badge = "red.gif"
} else if (norm > 0 || low > 0) {
badge = "yellow.gif"
} else if (action.result.numberOfWarnings == 0) {
badge = "green.gif"
}
if (debug) {
println(badge + " " + label)
} else {
manager.addBadge(badge, label)
}
} else if (action.class.simpleName == "TestResultAction") {
def failed = action.result.failedTests.size()
def label = failed + " Failed Tests"
badge = "error.gif"
if (failed > 0) {
badge = "red.gif"
} else if (failed == 0) {
badge = "green.gif"
}
if (debug) {
println(badge + " " + label)
} else {
manager.addBadge(badge, label)
}
} else if (action.class.simpleName == "ViolationsBuildAction") {
// TODO: Improve this to break out the warning severities
// println(action.report.violations)
for (e in action.report.violations) {
def failed = e.value
def label = failed + " " + e.key + " Violations"
// println(label)
badge = "error.gif"
if (failed > 0) {
badge = "red.gif"
} else if (failed == 0) {
badge = "green.gif"
}
if (debug) {
println(badge + " " + label)
} else {
manager.addBadge(badge, label)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment