0

I'm trying to retrieve the build data for a specific build with depth 2 but the default is always 1

J = Jenkins(host,user,password)
job = J.get_job(job_name)
build_number = job.get_last_good_build()

It's not mentioned in the documentation, only how to create build object with depth 2.

How do I get it with depth 2 ?

shanwar
  • 319
  • 1
  • 2
  • 19

3 Answers3

0

I don't think the API has it by default. Best thing I can think of is to get a list of all jobs, and query each on for a success, if your job fails often you could start with the last_good_build and work your way down/

I don't know Python that well, but I wrote a very bad script in GO to get all successful builds, you'd just have to add logic to stop at depth 2:

You would have to do something like:

    builds, err := jenkins.GetAllBuildIds(jobName)
    var count int64
    if err != nil {
        panic(err)
    }
    for _, build := range builds {
        buildID := build.Number
        data, err := jenkins.GetBuild(jobName, buildID)
        if err != nil {
            panic(err)
        }

        if "SUCCESS" == data.GetResult() {
            <LOGIC>
        }
theoneandonlyak
  • 490
  • 4
  • 7
0

Simply use foward slash / to separate nested jobs. It will work for directories and Organization plugins, such as Bitbucket Team Project.

job = J.get_job("{}/{}".format(organization, job_name))
Majus Misiak
  • 643
  • 7
  • 14
0

In the latest version of the Jenkins API for Python there is the method get_job_info. It has the input argument depth.

By the user Sven Krüger

shanwar
  • 319
  • 1
  • 2
  • 19