Created
May 2, 2012 15:50
-
-
Save mheiges/2577683 to your computer and use it in GitHub Desktop.
Groovy script to skip build if other job is failed
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
/** | |
Checks the last build status of a sentinel job and if worse than expected, | |
aborts the job running this script. | |
Example usage. Use this script in a pre-scm build step (using pre-scm plugin) for | |
qa.eupathdb.org . Configure the qa.eupathdb.org job to use the integrate.eupathdb.org | |
job as a sentinel_job. If the last build of integrate.eupathdb.org is worse than | |
expected when a qa.eupathdb.org build is started then abort the qa.eupathdb.org | |
build so it doesn't pick up the bad code that failed the sentinel job. | |
Requires a variable binding for sentinel_job in the pluging | |
configuration for Groovy script file. e.g. | |
sentinel_job=integrate.somedb.org | |
**/ | |
import hudson.model.* | |
def expected = Result.UNSTABLE | |
def thisThread = Thread.currentThread() | |
def thisBuild = thisThread.executable | |
try { | |
sentinel_job | |
} catch (MissingPropertyException e) { | |
println("\n\n") | |
println("Binding variable 'sentinel_job' is missing.") | |
println("Add this in the job's configuration for Groovy script file (under Advanced). e.g.") | |
println("sentinel_job=integrate.job.org") | |
println("\n\n") | |
thisThread.interrupt() | |
return | |
} | |
def sentinelJobName = sentinel_job | |
def sentinelJob = hudson.model.Hudson.instance.getJob(sentinelJobName) | |
def sentinelResult = sentinelJob.getLastBuild().result | |
println("\n") | |
if (sentinelResult.isWorseThan(expected)) { | |
println("Last build of sentinel job " + sentinelJobName + " was " + sentinelResult + ". Aborting this build.\n") | |
thisThread.interrupt() | |
return | |
} | |
println("Last build of " + sentinelJobName + " was " + sentinelResult + ". Continuing with this build.\n") | |
return true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment