How to limit Jenkins API response to last n build IDs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to limit Jenkins API response to last n build IDs

Raghav-2

Hi,


http://xxx/api/xml?&tree=builds[number,description,result,id,actions[parameters[name,value]]]


Above API returns all the build IDs. Is there a way to limit results to get last 5 build IDS?


Thanks,

Raghav

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6a07cdb2-6319-421b-8649-ee8ceaaacc19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to limit Jenkins API response to last n build IDs

Daniel Beck

> On 21. Dec 2017, at 19:05, Raghav <[hidden email]> wrote:
>
> Above API returns all the build IDs. Is there a way to limit results to get last 5 build IDS?

See the documentation at the /api/ URL, section 'Controlling the amount of data you fetch'.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/459975AC-3D0E-47BA-9D9A-99D6A4308366%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to limit Jenkins API response to last n build IDs

Raghav-2
In reply to this post by Raghav-2

The tree query parameter allows you to explicitly specify and retrieve only the information you are looking for, by using an XPath-ish path expression. The value should be a list of property names to include, with sub-properties inside square braces. Try tree=jobs[name],views[name,jobs[name]] to see just a list of jobs (only giving the name) and views (giving the name and jobs they contain). Note: for array-type properties (such as jobs in this example), the name must be given in the original plural, not in the singular as the element would appear in XML (<job>). This will be more natural for e.g. json?tree=jobs[name] anyway: the JSON writer does not do plural-to-singular mangling because arrays are represented explicitly.

For array-type properties, a range specifier is supported. For example, tree=jobs[name]{0,10} would retrieve the name of the first 10 jobs. The range specifier has the following variants:

  • {M,N}: From the M-th element (inclusive) to the N-th element (exclusive).
  • {M,}: From the M-th element (inclusive) to the end.
  • {,N}: From the first element (inclusive) to the N-th element (exclusive). The same as {0,N}.
  • {N}: Just retrieve the N-th element. The same as {N,N+1}.

Another way to retrieve more data is to use the depth=N query parameter . This retrieves all the data up to the specified depth. Compare depth=0 and depth=1 and see what the difference is for yourself. Also note that data created by a smaller depth value is always a subset of the data created by a bigger depth value.

Because of the size of the data, the depth parameter should really be only used to explore what data Jenkins can return. Once you identify the data you want to retrieve, you can then come up with the tree parameter to exactly specify the data you need.


Source: http://ci.citizensnpcs.co/api/


On Thursday, December 21, 2017 at 12:05:37 PM UTC-6, Raghav wrote:

Hi,


<a href="http://xxx/api/xml?&amp;tree=builds[number,description,result,id,actions[parameters[name,value]]]" rel="nofollow" style="font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(0,89,153)" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fxxx%2Fapi%2Fxml%3F%26tree%3Dbuilds%5Bnumber%2Cdescription%2Cresult%2Cid%2Cactions%5Bparameters%5Bname%2Cvalue%5D%5D%5D\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH-okSHfp8zzuPI_gGpDeS1ZpR3Og&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fxxx%2Fapi%2Fxml%3F%26tree%3Dbuilds%5Bnumber%2Cdescription%2Cresult%2Cid%2Cactions%5Bparameters%5Bname%2Cvalue%5D%5D%5D\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH-okSHfp8zzuPI_gGpDeS1ZpR3Og&#39;;return true;">http://xxx/api/xml?&tree=builds[number,description,result,id,actions[parameters[name,va<a href="http://xxx/api/xml?&amp;tree=builds[number,description,result,id,actions[parameters[name,value]]]" rel="nofollow" style="font-family:inherit;font-size:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;color:rgb(0,89,153)" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fxxx%2Fapi%2Fxml%3F%26tree%3Dbuilds%5Bnumber%2Cdescription%2Cresult%2Cid%2Cactions%5Bparameters%5Bname%2Cvalue%5D%5D%5D\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH-okSHfp8zzuPI_gGpDeS1ZpR3Og&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fxxx%2Fapi%2Fxml%3F%26tree%3Dbuilds%5Bnumber%2Cdescription%2Cresult%2Cid%2Cactions%5Bparameters%5Bname%2Cvalue%5D%5D%5D\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH-okSHfp8zzuPI_gGpDeS1ZpR3Og&#39;;return true;">lue]]]

 


Above API returns all the build IDs. Is there a way to limit results to get last 5 build IDS?


Thanks,

Raghav

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/88e44b0d-688b-4437-9c1c-f25b298a0efb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.