Skip to content

Instantly share code, notes, and snippets.

@tizki
Created December 28, 2017 09:36
Show Gist options
  • Save tizki/dbf5c9db93de3d8cfa73da39d600ca8f to your computer and use it in GitHub Desktop.
Save tizki/dbf5c9db93de3d8cfa73da39d600ca8f to your computer and use it in GitHub Desktop.
The following script prints the time each build spent in the queue
def jenkins = Jenkins.instance
def jobName = PUT_YOUR_JOB_NAME
def job = jenkins.getItem(jobName)
def builds = job.getBuilds()
builds.each { build ->
def action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
def timeInQ = action.getQueuingDurationMillis()
def totalTimeInQ
if (timeInQ > 60000){
totalTimeInQ = "${timeInQ / 60000} minutes"
}
else{
totalTimeInQ = "${timeInQ / 1000} seconds"
}
println "${build.number} ${totalTimeInQ}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment