Corbell
Corbell

Reputation: 1393

python-jenkins get_job_info - how do I get info on more than 100 builds?

I'm using the python-jenkins api to manage some jenkins build servers. The servers are pretty loaded - scores of jobs and some jobs have saved hundreds of builds.

A basic goal I have is to use the API to get the build count for each job, and a total build count across all jobs. Here's the code:

import jenkins
jnk = jenkins.Jenkins(myUrl, myUsername, myPassword)
info = jnk.get_info()
jobs = info['jobs']
totalBuildCount = 0

for job in jobs:
    jobName = job['name']
    jobinfo = jnk.get_job_info(jobName)
    builds = jobinfo['builds'] # never contains more than 100 items
    print jobName + " build count: " + str(len(builds))
    totalBuildCount += len(builds)

print "Total build count: " + str(totalBuildCount)

What I find - unfortunately - is that the builds array in the job info dictionary never contains more than 100 entries, even if the job has stored many more builds than that.

Have others seen this limit, and is there any way around it, or is this API just useless for servers with large archived build counts?

Upvotes: 3

Views: 11886

Answers (2)

Andrey
Andrey

Reputation: 66

When using python-jenkins module to fetch more than 100 builds call get_job_info function with fetch_all_builds=True

Upvotes: 1

DevC
DevC

Reputation: 7423

If could use jenkinsapi instead:

from jenkinsapi.jenkins import Jenkins
jnk = Jenkins(myUrl, myUsername, myPassword)
totalBuildCount = 0

for job in jnk.keys():
    builds = jnk[job].get_build_dict()
    print job + " build count: " + str(len(builds))
    totalBuildCount += len(builds)

print "Total build count: " + str(totalBuildCount)

Upvotes: 0

Related Questions