简体   繁体   中英

How to get last build date of a job from Jenkins in Java

I have a job scheduled in Jenkins and it has lets say 370 total builds. I can see the date right next to build number in the build history part of the page but when I try to access the JSON content of that page like http:localhost:8080/job/job_name/api/json I am not getting that date for the latest build in that JSON content.

Any other way to access the date when the last build happended?

I have to use the same in Java so might be there is any API to access the Jenkins?

As Harshavardhan Konakanchi mentioned in his answer there's the /lastBuild/ URL path. You can get exactly the information you want by using:

<JENKINS_URL>/job/<JOB_NAME>/lastBuild/api/json?tree=timestamp

Example output:

{"timestamp":1467898403630}

See <JENKINS_URL>/job/<JOB_NAME>/lastBuild/api/ for a description of the API.

I am not sure whether this could solve you out or not, but here is my workaround

Access url /job/<job_name>/lastBuild/api/json retrieve timestamp

Convert epoch time to required date-time format

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