I would like to make an API call to Jenkins to fetch a list of builds along with their parameters and status. We currently pass a git commit sha1 as a parameter to build a specific branch. Any ideas how I can get this information easily?
Defining Build Parameters Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.
You can generate the parameter pipeline code block easily using the Jenkins pipeline generator. You will find the Pipeline syntax generator link under all the pipeline jobs, as shown in the image below. Navigate to the pipeline generator in Jenkins and under steps, search for properties, as shown below.
Go to Script Console under Manage Jenkins, this script will print the name of all jobs including jobs inside of a folder and the folders themselves: Jenkins. instance. getAllItems(AbstractItem.
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("")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With