Skip to content

Instantly share code, notes, and snippets.

@batmat
Last active June 3, 2024 04:27
Show Gist options
  • Save batmat/91faa3201ad2ae88e3d8 to your computer and use it in GitHub Desktop.
Save batmat/91faa3201ad2ae88e3d8 to your computer and use it in GitHub Desktop.
Quick Jenkins system groovy script to compute how many minutes of build you had in the last N hours
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