Skip to content

Instantly share code, notes, and snippets.

@sturman
Last active November 9, 2021 10:54
Show Gist options
  • Save sturman/046f6cb7c0297c4e134d826deb627c28 to your computer and use it in GitHub Desktop.
Save sturman/046f6cb7c0297c4e134d826deb627c28 to your computer and use it in GitHub Desktop.
List all Jenkins jobs and count build duration for each in sum for a period of time
def daysBefore = 30
def currentMillis = System.currentTimeMillis()
def cutOfDate = System.currentTimeMillis() - 1000L * 60 * 60 * 24 * daysBefore
long sumDurationMillis = 0
for (job in Jenkins.instance.getAllItems(Job.class)) {
def job_name = job.getFullName()
long durationMillis = 0
builds = job.getBuilds().byTimestamp(cutOfDate, currentMillis)
builds.each { build ->
durationMillis+= build.duration
}
println("$job_name --> $durationMillis")
sumDurationMillis += durationMillis
}
def sumDurationMinutes = sumDurationMillis / 1000 / 60
println "\nsumDurationMillis --> $sumDurationMillis"
println "sumDurationMinutes --> $sumDurationMinutes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment