Search code examples
tfsazure-devopstfsbuildazure-devops-rest-apitfs-sdk

Get builds from TFS-API using top - Parameter


I want to get a list of the last builds of my TFS. The API in general works well - but I don't understand the working of the "$top"-Parameter.

If I use a simple API call without the top-Parameter:

https://mytfs/project/_apis/build/builds?buildQueryOrder=finishTimeAscending

I get the max amount of 1000 results, correctly ordered with the newest on top/first.

If I add the $top-Parameter:

https://mytfs/project/_apis/build/builds?$top=10&buildQueryOrder=finishTimeAscending

I get 10 results - but not the first 10 from the larger list - but 10 random results (but always the same 10 - thus not really random). But this are not the newest 10 or the oldest 10 - just 10 out of 1000.

Am I understanding the $top-Parameter wrong? Or is this a bug in the TFS API?


Solution

  • Update

    Sorry for the misunderstanding. This is by design just as the description. It will only return the maximum number of builds not with a sequence order of return results.

    In other words, if you use $top Parameter, it will fetch 10 results of all build results and then order the returned the 10 results. It will not first order all build results and then fetch the top 10 of the ordered build results. Maybe that's where the confusion is.

    For what you are looking for, it's not available with existing parameter. You could only get the max amount of 1000 results with correctly ordered first. Finally fetch 10 of them.


    The $top parameter not work as the literal meaning. It will just return the maximum number of builds.

    $top integer int32 The maximum number of builds to return.

    You could refer the official doc here: Builds - List