Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Jenkins Groovy Postbuild script
import hudson.model.*
import com.tikal.jenkins.plugins.multijob.*;
void log(msg) {
threshold = Result.SUCCESS
void aggregate_results() {
failed = false
mainJob =
job = hudson.model.Hudson.instance.getItem(mainJob)
log "---------------------------------------------------------------------------------------------------------------"
log "Aggregated status report"
log "---------------------------------------------------------------------------------------------------------------"
log("${mainJob} #${} - ${}")
job.getLastBuild().getSubBuilds().each { subBuild->
subJob = subBuild.getJobName()
subJobNumber = subBuild.getBuildNumber()
job = hudson.model.Hudson.instance.getItem(subBuild.getJobName())
log "${subJob} #${subJobNumber} - ${job.getLastCompletedBuild().getResult()}"
log job.getLastCompletedBuild().getLog()
//println subBuild
dePhaseJob = hudson.model.Hudson.instance.getItem(subBuild.getJobName())
dePhaseJobBuild = dePhaseJob.getBuildByNumber(subBuild.getBuildNumber())
dePhaseJobBuild.getSubBuilds().each { childSubBuild ->
try {
log " ${childSubBuild.jobName}"
job = hudson.model.Hudson.instance.getItem(childSubBuild.getJobName())
build = job.getBuildByNumber(childSubBuild.getBuildNumber())
indent = " "
log "${indent} #${build.getNumber()} - ${build.getResult()}"
log build.getLog()
if(!failed && build.getResult().isWorseThan(threshold) ) {
failed = true
} catch (Exception e) {
log("ERROR: ${e.getMessage()}")
failed = true
if(failed) {}
try {
} catch(Exception e) {
log("ERROR: ${e.message}")
log("ERROR: Failed Status report aggregation")

rozagh commented Nov 8, 2013

I am getting this error, is there any API changes?

ERROR: No signature of method: hudson.maven.MavenModuleSetBuild.getSubBuilds() is applicable for argument types: () values: []
Possible solutions: getNextBuild(), getNextBuild(), getRootBuild(), getModuleBuilds()
ERROR: Failed Status report aggregation
Build step 'Groovy Postbuild' changed build result to FAILURE
Build step 'Groovy Postbuild' marked build as failure

Thank you for showing me how to log! Took me forever to figure out :)

Hey @rozagh, I know it's been a very long time, but have you figured out a workaround for your issue? I'm facing the same problem. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment