Is it possible to get Jenkins build duration using scripts or using some inbuilt functionality. I tried with ${BUILD_DURATION}
but it didn't work.
Can anyone please suggest?
Here are a couple of options:
RESTFUL API
Use a language of your choice to consume Jenkins Restful API to get the json for the build and deserialise.
DECLARATIVE PIPELINE
Use ${currentBuild.durationString}
.
The currentBuild object exposes a number of relevant attributes:
timeInMillis:
time since the epoch when the build was scheduled
startTimeInMillis
time since the epoch when the build started running
duration
duration of the build in milliseconds
durationString
a human-readable representation of the build duration
Navigate to https://<your-jenkins-instance>/pipeline-syntax/globals#currentBuild
for the complete list.
I am Jenkins beginner & below Groovy script is an easy approach;
def item = Jenkins.instance.getItem("<Job_name>")
def last_job_duration = item.getLastBuild().getDurationString()
println last_job_duration
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