Skip to content

Instantly share code, notes, and snippets.

@batmat
Last active November 16, 2021 14:03
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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