I have a hosted Jenkins server and from there, I am trying to fetch the build details (like result, timestamp, duration etc.) for all the jobs using the Jenkins REST API and then save it in my database.
Right now, I am calling the following API from my Java code, to fetch all the jobs (about 200 jobs):
https://<JENKINS_HOST>/api/json
Then I fetch the job details and all the builds for each job by using:
https://<JENKINS_HOST>/job/MY_JOB/api/json
Then finally, for each of the builds (I have to fetch only last 50), I have to call this to fetch the build details:
https://<JENKINS_HOST>/job/MY_JOB/<BUILD_NUMBER>/api/json
So that makes it about a total of 50*200 + 201 = over 10000 API calls.
I am guessing, These many API calls would make the Jenkins server perform slow?
So, my question is is there a faster/more optimal way to do this, So that I do not have to make so many API calls?
Something like where I can fetch all the build details using one url like this: (hypothetically)
https://<JENKINS_HOST>/job/MY_JOB/api/json?fetchAllbuildDetails=True
In case, anyone else is stuck with the same, I was able to get this done using the tree:
https://<JENKINS_HOST>/api/json?tree=jobs[name,url,builds[number,result,duration,url]]
Here, column names can be filtered to fetch only the data you need as the amount of data returned from this is huge.
You can also limit the number of records to be fetched like this:
https://<JENKINS_HOST>/api/json?tree=jobs[name,url,builds[number,result,duration,url]{0,50}]
This will fetch only the last 50 builds for all the jobs, which is exactly what I needed.
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