Last active
November 4, 2021 19:40
-
-
Save cmaggiulli/4eaf3a563863dc59db2204420faed0e5 to your computer and use it in GitHub Desktop.
Get All Builds with Build Description Jenkins Script Console
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 will print the job name and build number of all jobs in the last N days for all builds with a non null description. | |
| * This script is useful for locating builds that have been earmarked with a build description. | |
| * Example: Assume you have a build that runs every 2 minutes but 90% of the builds do not produce any artifacts. If you earmark the | |
| * builds that produce artifacts by setting a build description you can then use this script to locate all the artifact-producting builds. | |
| * | |
| * Note: We are filtering on build description, which is different from a projects description | |
| * | |
| */ | |
| final jenkins = Jenkins.instance | |
| final lookBack = -1 // Number of days to look back | |
| // Using legacy Calendar instead of Instant due hudson.model.Run.timestamp parameter | |
| final before = Calendar.instance | |
| final after = Calendar.instance | |
| before.add( Calendar.DATE, 0 ) // today | |
| after.add( Calendar.DATE, lookBack ) // today - N days | |
| before.setTime( before.time ) | |
| after.setTime( after.time ) | |
| println sprintf("Jobs executed between %s and %s with a non-null build description", before.time, after.time) | |
| jenkins.getAllItems( Job.class ).each{ job -> | |
| job.builds.findAll{ run -> run.timestamp?.before( before ) && run.timestamp?.after( after ) && run.description != null }.each { run -> | |
| println sprintf( "%s | %o | %s | %s", job.name, run.number, run.description, run.time ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment