Skip to content

Instantly share code, notes, and snippets.

@thomaschaplin
Last active November 16, 2021 14:05
Show Gist options
  • Select an option

  • Save thomaschaplin/959a02c9dae7ba5e62211cb792c318c8 to your computer and use it in GitHub Desktop.

Select an option

Save thomaschaplin/959a02c9dae7ba5e62211cb792c318c8 to your computer and use it in GitHub Desktop.
Get the total build time of Jenkins jobs
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