Jenkins gets a list of assemblies and parameters

I would like to make a Jenkins API call to get the list of assemblies along with my parameters and status. We are currently passing git commit sha1 as a parameter to build a specific branch. Any ideas how I can easily get this information?

+7
source share
3 answers

Jenkins provides a nice ah.

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 
+7
source

As far as I know, this cannot be done in a single API call.

First request all assemblies.

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

This will return xml or json output, respectively.

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

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

You can then verify the SHA as a result against your SHA.

+2
source

Combining @ user1255162 comment for the answer. I had to request many assemblies and print its parameter for the report. Here is a piece of code in a clockwork

 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("") } 
0
source

Source: https://habr.com/ru/post/945105/


All Articles