Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
| // 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 | |
| '' |