I want to use the jenkins API to get information about my current jobs. I can find information on the last build (.../job/MyJob/lastBuild/api/xml
) but I'm not seeing the field(s) that would let me create a progress bar. I see an estimatedDuration
field and a building
field, but nothing that tells me how long it's already been running.

- 354
- 4
- 11

- 370,779
- 53
- 539
- 685
4 Answers
Here's the URL that gives me the information I need:
http://<host>/job/<jobname>/lastBuild/api/xml?tree=timestamp,estimatedDuration
Which yields something like:
<freeStyleBuild>
<estimatedDuration>86126</estimatedDuration>
<timestamp>1350615637401</timestamp>
</freeStyleBuild>

- 370,779
- 53
- 539
- 685
-
2I noticed that this only shows for when the build is complete, is there a feed to get live updates on the percent complete of the build? For instance when a person initiates a build i can emulate the jenkins progress bar on another website? – BLang Jan 26 '18 at 03:16
For me is also working by getting a json:
http://<host>/job/<jobname>/lastBuild/api/json?tree=executor[progress]

- 1,412
- 1
- 18
- 28
I came across this question while trying to retrieve the percentage. As I figured out a solution, I thought I would post it here.
The response includes two fields, timestamp
(time the job started) and estimatedDuration
(milliseconds).
If you take the current time, you can subtract the timestamp
from the current time. This will give you the number of milliseconds since the job started. Using this calculated value, you can compare it with the estimatedDuration
field and thus determine the percentage complete.
So the formula would be (where data is a JSON object of the returned data):
Console.log(" complete: " + Math.round((new Date().getTime() - data.timestamp) / data.estimatedDuration * 100) + "%");
Your using XML and not JSON, but I'm sure it's a similar structure.
I'm using the following lib in node.js: https://github.com/jansepar/node-jenkins-api
My logic is:
var jenkinsapi = require('./lib/jenkins');
var jenkins = jenkinsapi.init("http://jenkins.myServer.com:8080");
jenkins.last_result('/myProj', function(err, data) {
if(err) {
console.log("last result kitchen_ellipse: ERROR (last result): " + data.statusCode);
return;
}
console.log("progress " + data.fullDisplayName + " number: #" + data.number +
+ " complete: " +
Math.round((new Date().getTime() - data.timestamp) /
data.estimatedDuration * 100) + "%"
+ " result: " + data.result);
});

- 3,998
- 5
- 37
- 61
-
I keep getting 404 using the last_result() call, if i have a job named, 'jobA', how do you pass it to last_result? Because if i use the function, last_build_info, i just pass it as last_build_info('jobA'), but if i do last_result('jobA') or last_result('/jobA') i get 404. – BLang Jan 26 '18 at 04:07
-
Sorry BLang, it's been a long time since I last looked at this. I had a quick look through my old lib and the above is how I was doing it. You can see my old code at https://github.com/jamesjenner/Vor/blob/master/lib/server/jenkins.js. It was working back in those days. Just no idea now a days sorry. – Metalskin Jan 29 '18 at 02:49
-
1no worries, i actually figured out a solution and when i finish/ get it stable, ill be posting to the thread i created here: https://stackoverflow.com/questions/48455608/live-feed-of-jenkins-job-progress-bar – BLang Feb 20 '18 at 16:20
use following :
http://<host>/job/<jobname>/lastBuild/api/xml?depth=1&xpath=*/executor/progress/text()
this will return you the progress in percentage
ex : 27
similarly you can get other parameters like user, id(build number), timestamp etc.
you can find them using following url:
http://<host>/job/<jobname>/lastBuild/api/xml?depth=1
above url returns an xml where all the required parameter ,from last build, are listed.

- 107
- 1
- 6