简体   繁体   中英

How to get Jenkins build job duration

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.

Jenkins UI 中显示的构建持续时间

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM