Jenkins get list of builds and parameters

As far as I know, this can't be done in a single API call.

First query all builds.

/job/<jobname>/api/xml
/job/<jobname>/api/json

This will return xml or json output, respectively.

Once you get the build numbers, you can query each build number.

/job/<jobname>/<jobnum>/api/xml?xpath=/freeStyleBuild/action/lastBuiltRevision/SHA
/job/<jobname>/<jobnum>/api/json?tree=actions[lastBuiltRevision[SHA]]

Then you can check the SHA in the result against your SHA.


Jenkins provides a nice api.

It is documented at:

http://$HOST/jenkins/api

You probably want something like:

http://$HOST/jenkins/api/xml?xpath=/hudson/job[1]/build[1]/action[1]/parameter&depth=2

Combining @user1255162 's comment to an answer. I had to query set of builds and print its parameter for a report. Here is the code snippet in groovy

import groovy.json.JsonSlurper


def root = "<url to job>"
def options = "/api/json?tree=builds[actions[parameters[name,value]],result,building,number,duration,estimatedDuration]"

def jsonSlurper = new JsonSlurper()
def text = new URL("${root}/${options}").text
def data = jsonSlurper.parseText(text)

data["builds"].each { buildsdata ->
    def result = buildsdata["result"]
    def num = buildsdata["number"]
    print("${root}/${num}/parameters  |")
    buildsdata["actions"].each { actions ->
        if (actions["_class"].equals("hudson.model.ParametersAction")) {
            actions["parameters"].sort({it.name}).each { param ->
                    print("${param.name}=${param.value}|")
            }
        }
    }
    println("")
}

Tags:

Api

Jenkins