Skip to content

Instantly share code, notes, and snippets.

@dnozay
Created January 22, 2015 18:39
Show Gist options
  • Save dnozay/898b05f6ee32151b78f3 to your computer and use it in GitHub Desktop.
Save dnozay/898b05f6ee32151b78f3 to your computer and use it in GitHub Desktop.
jenkins - scan jobs and find if last build was aborted (e.g. maintenance) and who aborted it.
// scan all jobs and check if the last build was aborted (e.g. maintenance)
// and output user / timestamp
jobs = Jenkins.instance.getAllItems()
lastabort = null
jobs.each { j ->
if (j instanceof com.cloudbees.hudson.plugins.folder.Folder) { return }
numbuilds = j.builds.size()
if (numbuilds == 0) { return }
lastbuild = j.builds[numbuilds - 1]
if (lastbuild.result == Result.ABORTED) {
println 'JOB: ' + j.name
abortCause = lastbuild.getAction(InterruptedBuildAction).getCauses()[0]
println ' -> lastbuild: ' + lastbuild.displayName + ' = ' + lastbuild.result + ', cause: ' + abortCause.shortDescription + ', time: ' + lastbuild.timestampString2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment