How to use tree query parameter in Jenkins Remote API to get downstreamProject and parameter?

Ghasfarost picture Ghasfarost · Feb 15, 2012 · Viewed 11.5k times · Source

I am trying to use Jenkins(Hudson) Remote API to consume XML response from a freeStyleProject.

Researching about the tree query parameter in the Jenkins documentation and here I have been trying to use it to improve response times to get XML response. But Jenkins seems to be unable to generate the nodes downstreamProject of the job and the action/parameter of the builds with this URL:

http://localhost/job/MyJob/api/xml?depth=2&tree=name,description,builds[action[parameter[name,value]]number,url,timestamp,result],healthReport[score,description],downstreamProject[name,url]

I just get this response XML:

<freeStyleProject>
    <description>Description</description> 
    <name>MyJob</name> 
    <build>
        <number>2</number> 
        <result>SUCCESS</result> 
        <timestamp>1325784290000</timestamp> 
        <url>http://localhost/job/MyJob/2/</url> 
    </build>
    <build>
      <number>1</number> 
      <result>SUCCESS</result> 
      <timestamp>1323931754000</timestamp> 
      <url>http://localhost/job/MyJob/1/</url> 
    </build>
    <healthReport>
       <description>Build stability: No recent builds failed.</description> 
       <score>100</score> 
    </healthReport>
</freeStyleProject>

Perhaps the tree query parameter does not support these? Would the only way to get this nodes using the xpath and exlude query parameters?

Answer

LifesCircus picture LifesCircus · Jul 27, 2012

For the "tree" parameter, the pieces you are looking for are plurals (where you have singulars).

action => actions

parameter => parameters

downstreamProject => downstreamProjects

So, your url would be:

http://localhost/job/MyJob/api/xml?depth=2&tree=name,description,builds[actions[parameters[name,value]],number,url,timestamp,result],healthReport[score,description],downstreamProjects[name,url]