0

I am trying to use the jenkins API to retrieve a list of running jobs buildURLs and this works with this the query https://jenkins.server.com/computer/api/xml?tree=computer[executors[currentExecutable[url]]]&depth=1&xpath=//url&wrapper=buildUrls

By searching for all executors on given jenkins server and then grabbing the urls and wrapping them in a xml buildUrls object

(what I actually want is a count of total running jobs but I can filter in api then get a .size of this once client side)

However the application I am uses only accepts json, although I could convert to json I am wondering if there is a way I can have this return a json object which contains just the buildUrls. Currently if I change return to json the xpath modification is removed (since its xml only) And I instead get returned the list of all executors and their status

I think my answer lies within Tree but i cant seem to get the result I want

Froodle
  • 339
  • 2
  • 5
  • 15

1 Answers1

0

To return a JSON object you can modify the URL as below

http://jenkins.server.com/computer/api/json?tree=computer[executors[currentExecutable[url]]]&depth=1&pretty=true

It will not be possible to get only the build urls you need to iterate through all the executables to get the total running jobs. The reason is that build urls alone cannot give you information where it is running. Hence, unfortunately we need to iterate through each executor.

The output you will get is something like below.

JSON Output

Another way of doing this same thing is parsing via jobs http://jenkins.server.com/api/json?tree=jobs[name,url,lastBuild[building,timestamp]]&pretty=true You can check for building parameter. But here too you will not be able to filter output from url diretly in jenkins. Iteration would be required through each and every job.

Siddharth Kaul
  • 871
  • 10
  • 20