For the statistics, I want to see how long the job is in the waiting queue, therefore I can tune the system to make the job is run in time.
If the job is just in queue, it is possible to find in waiting queue in front page see How can I tell how long a Jenkins job has been in the wait queue?
Or the http://<jenkins_url>/queue/api/json?pretty=true
Is it possible to check somewhere to get "Time waiting in queue" for the specific job after the job is finished ?
Will be nice if it can be gotten in public jenkins API.
You can use ${currentBuild. durationString} to get build duration.
You can set timeout duration for a particular project by defining a global timeout variable and using it in your job. Go to Manage Jenkins > Configure System and in Global Properties check Environment Variables , then add a variable (ex: EXEC_TIME_OUT) to it and assign the timeout amount.
// got answer from colleague
It can be achieved by installing Jenkins Metrics Plugin, after it is installed, in the build result page, you will see
Jenkins REST API: Then you can get wait time in queue from http://localhost:8080/job/demo/1/api/json?pretty=true&depth=2 . queuingDurationMillis
is the data I wanted.
"actions" : [
{
"queuingDurationMillis" : 33,
"totalDurationMillis" : 3067
}
],
Groovy script: Also we can get this data in groovy via internal data, check below code in Jenkins Script console http://localhost:8080/script
job = hudson.model.Hudson.instance.getItem("demo")
build = job.getLastBuild()
action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
println action.getQueuingDurationMillis()
You can see the demo using docker by running below and open in browser for demo
job
docker run -it -p 8080:8080 larrycai/jenkins-metrics
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With