Last active
April 5, 2019 13:58
-
-
Save halyph/4610274 to your computer and use it in GitHub Desktop.
Jenkins Groovy Postbuild script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
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
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