Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve all previous builds for a Jenkins job through the API?

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

like image 648
miwiwa Avatar asked Feb 22 '18 06:02

miwiwa


People also ask

How do I create a job in Jenkins?

Creating jobs by sending xml file or by specifying params as options with more customization options including source control, notifications, etc. Building jobs (with params), stopping builds, querying details of recent builds, obtaining build params, etc. Listing jobs available in Jenkins with job name filter, job status filter.

How to recover from a failed Jenkins build?

If the job is a jenkins pipeline, open the failed build and select the Replay option. Otherwise select the Rebuild option. Thanks for contributing an answer to DevOps Stack Exchange!

What are the best practices for Jenkins job management?

Building jobs (with params), stopping builds, querying details of recent builds, obtaining build params, etc. Listing jobs available in Jenkins with job name filter, job status filter. Adding/removing downstream projects. Chaining jobs i.e given a list of projects each project is added as a downstream project to the previous one.

How do I check how long a Jenkins job takes to run?

If you want to know how long a job takes to run, then you need to get down to the build level. To get build metadata, you need to call get_build_info (). This method takes in the job name and the build number and returns the metadata as a dictionary. You can do a lot more with the Python Jenkins package.


1 Answers

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.

like image 183
SV Madhava Reddy Avatar answered Oct 12 '22 06:10

SV Madhava Reddy