Skip to content

Instantly share code, notes, and snippets.

@rajendrapenumalli
Forked from dnozay/_Jenkins+Script+Console.md
Created August 31, 2018 04:01
Show Gist options
  • Select an option

  • Save rajendrapenumalli/acb32dba6fd07a45f0c6c205b04be816 to your computer and use it in GitHub Desktop.

Select an option

Save rajendrapenumalli/acb32dba6fd07a45f0c6c205b04be816 to your computer and use it in GitHub Desktop.
jenkins groovy scripts collection.
// scan all jobs and check if the last build was aborted (e.g. maintenance)
// and output user / timestamp
jobs = Jenkins.instance.getAllItems()
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
}
}
''
// list jobs and their last build.
jobs = Jenkins.instance.getAllItems()
jobs.each { j ->
if (j instanceof com.cloudbees.hudson.plugins.folder.Folder) { return }
println 'JOB: ' + j.name
numbuilds = j.builds.size()
if (numbuilds == 0) {
println ' -> no build'
return
}
lastbuild = j.builds[numbuilds - 1]
println ' -> lastbuild: ' + lastbuild.displayName + ' = ' + lastbuild.result + ', time: ' + lastbuild.timestampString2
}
// returns blank
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment