Search code examples
restjenkins

Jenkins REST API to retrieve completed job info


I am simply trying to retrieve completed job info including the job result and have looked at many articles and still I can't get the completed job info. The latest url I tried is as follows:

https://<myjenkinsserver>/jenkins/<jenkinsinstancename>/api/json/&pretty=true&depth=3&tree=builds[actions[parameters[name,value]],number,result,building]

but still I get nothing that looks at all like what I am looking for. Everything I am seeing appears to be the static jobs defined, not the completed results of the jobs because there is no job number in the results that I see which has to be there if I want to query the results of a completed job!

Here is a snippet of what I get back:

{"_class":"hudson.model.Hudson","assignedLabels":[{"name":"docker"},{"name":"master"}],"mode":"EXCLUSIVE","nodeDescription":"the master Jenkins node","nodeName":"","numExecutors":4,"description":null,
"jobs":[{"_class":"hudson.model.FreeStyleProject","name":"build_GBO","url":"https://<jenkinsserver>/jenkins/<jenkinsinstance>/job/API_build_GBO/","color":"disabled"},...

Thoughts?

Thanks, Don Bouchard


Solution

  • It is easier to write URL for per job basis. For the URL as follows:

    http://jenkinsinstance:9090/job/JOB_NAME/api/json?tree=builds[number,result,duration,url,actions[parameters[name,value]]]
    

    The output will be as follows: You get

    1. Build
    2. Actions or Parameters for the build.
    3. duration for which the build executed.
    4. Build Number
    5. Build Results Pass or Fail
    6. url

    Build Results

    Edit: To get all jobs all results at the root level the url is

    http://jenkinsinstance/api/json?tree=jobs[name,url,builds[number,result,duration,url]]
    

    This will list all the jobs at root level. If you have folders as highlighted you can parse into those urls. all results