Last active
November 16, 2021 14:05
-
-
Save thomaschaplin/959a02c9dae7ba5e62211cb792c318c8 to your computer and use it in GitHub Desktop.
Get the total build time of Jenkins jobs
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
| def numberOfHoursBack = 7 * 24 | |
| def totalBuildTime = | |
| Jenkins.instance.getItems(Job.class).collect { | |
| job -> | |
| job.getBuilds().byTimestamp(System.currentTimeMillis() - numberOfHoursBack * 60 * 60 * 1000, System.currentTimeMillis()) | |
| } | |
| .flatten() | |
| .collect { | |
| build -> build.getDuration() | |
| } | |
| .sum() | |
| def totalBuildTimeInMinutes = (int) totalBuildTime / (60 * 1000) | |
| println "During the last $numberOfHoursBack hours" | |
| println "\t $totalBuildTimeInMinutes minutes total" | |
| println "\t ${totalBuildTimeInMinutes/numberOfHoursBack} minutes per hour in average" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment