Last active
November 9, 2021 10:54
-
-
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
This file contains 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 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