Created
June 3, 2019 12:48
-
-
Save okgolove/ccfe9b560ce9478b7016709071543065 to your computer and use it in GitHub Desktop.
Jenkins useful groovy commands
This file contains hidden or 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
| //This script allows you to get build information for selected jobs | |
| /* | |
| You can also add closures to filter the jobs or the builds... | |
| .find{job->job.name.contains('dsl')} | |
| .find{ [whatever]} | |
| */ | |
| Jenkins.instance.getAllItems(Job).each{ | |
| def jobBuilds=it.getBuilds() | |
| //for each of such jobs we can get all the builds (or you can limit the number at your convenience) | |
| jobBuilds.each { build -> | |
| def runningSince = groovy.time.TimeCategory.minus( new Date(), build.getTime() ) | |
| def currentStatus = build.buildStatusSummary.message | |
| def cause = build.getCauses()[0] //we keep the first cause | |
| //This is a simple case where we want to get information on the cause if the build was | |
| //triggered by an user | |
| def user = cause instanceof Cause.UserIdCause? cause.getUserId():"" | |
| //This is an easy way to show the information on screen but can be changed at convenience | |
| println "Cause: ${cause} | User: ${user}" | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment