1
votes

I would like to use the TeamCity REST API to query by project for failing, errored and successful builds. Basically I want to recreate this rollup in a separate application:

enter image description here

Is there any easy way to do this? The closest I could get was this query, but it has much more than the most recent failed build for a given build configuration:

http://teamcity:8111/app/rest/builds/?locator=<project id locator>,status:failure
2

2 Answers

2
votes

There is no such method currently in the REST API, there are two alternatives:

1) Request the list of build configs globally with one HTTP request, then for each build config in the project you want request the latest X builds for each of them - in your case X is 1 using

/httpAuth/app/rest/builds/?locator=buildType:BUILD_TYPE_ID&count=1

This will take 1 + N HTTP requests, N being the number of build types in the project and will always be correct.

2) Do something similar as you are already doing, then parse the response, group by build type id and take the latest one of each to do the rollup - there is a chance you might miss builds here if they are not in the first 100 most recent builds - you can extend the search scope using the count=XXX request parameter.

/httpAuth/app/rest/builds/?locator=project:(id:PROJECT_ID)&count=XXX

This will use 1 HTTP request, but may miss old builds

2
votes

With recent TeamCity versions (certainly 9.1.1 and newer) you could get all failed builds like this:

/httpAuth/app/rest/problemOccurrences?locator=affectedProject:<Project ID>,currentlyFailing:true

This results in a list of all currently failed builds with their build IDs. Then you can get details about each build like this:

/httpAuth/app/rest/builds/id:<Build ID>