8

I'm building a python script to pull build history data for Jenkins jobs. I've been successful with this using the Requests library to retrieve the json output, feed into a dataframe, and report on.

I'm noticing it's only pulling the last 100 builds, which looks like the default. I'm testing with a basic curl call, which works fine retrieving the last 100, to see how I can retrieve all builds. I've been searching Google and found one that said to add fetch_all_builds=True, but that still only pulls 100.

Does anyone know how I can request all the builds from a job through an API call?

Thanks

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
miwiwa
  • 105
  • 1
  • 4

1 Answers1

12

Adding tree=allBuilds will give you what you want.

<JENKINS URL>/job/<Job Name>/api/json?tree=allBuilds[*]&depth=2

This is the API Call URL.

SV Madhava Reddy
  • 1,858
  • 2
  • 15
  • 33
  • Thanks for the reply. How do I add depth to that as well? I tried `..../api/json?tree=allBuilds&depth=2` but it didn't work. – miwiwa Feb 22 '18 at 17:46
  • 1
    Actually I forgot to mention `[*]` in the url. If you do this, you will get all builds with data. You can do `tree=allBuilds[id,queueId]` for specifying which keys to return also. – SV Madhava Reddy Feb 23 '18 at 09:08
  • @miwiwa did this worked? It surely works. Because I am using the same. Is there any error you are getting or anything you want to mention? If everything is right, please accept someone's answer so that this thread can be closed. – SV Madhava Reddy Mar 30 '18 at 07:30
  • I get `{ _class: "com.cloudbees.hudson.plugins.folder.Folder" }` – Snowcrash Jun 11 '21 at 08:38
  • 1
    Using 'tree=allBuilds[*]&depth=2' returning all the builds of a job. But it does not return parameters value of each build. Using 'tree=allBuilds[parameters[name,value]]&depth=2' returns the below. "allBuilds" : [ { "_class" : "hudson.model.FreeStyleBuild" }, { "_class" : "hudson.model.FreeStyleBuild" }, { "_class" : "hudson.model.FreeStyleBuild" }, { "_class" : "hudson.model.FreeStyleBuild" }, ..... } – Jayakumari Arumugham Sep 30 '21 at 09:36