Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Jenkins Groovy Postbuild script

View postbuild.groovy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
import hudson.model.*
import com.tikal.jenkins.plugins.multijob.*;
 
void log(msg) {
manager.listener.logger.println(msg)
}
 
threshold = Result.SUCCESS
 
void aggregate_results() {
failed = false
 
mainJob = manager.build.getProject().getName()
job = hudson.model.Hudson.instance.getItem(mainJob)
 
log "---------------------------------------------------------------------------------------------------------------"
log "Aggregated status report"
log "---------------------------------------------------------------------------------------------------------------"
 
log("${mainJob} #${manager.build.getNumber()} - ${manager.build.getResult()}")
 
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) {manager.build.setResult(hudson.model.Result.FAILURE)}
}
 
try {
aggregate_results()
} catch(Exception e) {
log("ERROR: ${e.message}")
log("ERROR: Failed Status report aggregation")
manager.build.setResult(hudson.model.Result.FAILURE)
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.