13

I'm trying to get the latest successful build.

This request returns all of the successful builds for a specified buildType (as BUILDTYPE below).

/httpAuth/app/rest/builds/?locator=buildType:BUILDTYPE,status:SUCCESS

Is there a way to further filter out to get the single latest successful build of the corresponding buildType?

TeamCity Version: Professional 9.1.3 (build 37176)

HEADLESS_0NE
  • 3,416
  • 4
  • 32
  • 51

3 Answers3

13

Adding a count of 1 should work:

/httpAuth/app/rest/builds/?locator=buildType:BUILDTYPE,status:success,count:1
Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
Willcodeforfun
  • 361
  • 3
  • 10
  • Re-read my question please. What you've suggested returns all of the successful builds...I want the single latest successful build of the corresponding `buildType` – HEADLESS_0NE Mar 28 '16 at 20:15
  • The latest build is always stacked at the top of the response, right? It seems to work, thanks! – HEADLESS_0NE Mar 28 '16 at 20:30
  • How do we get the status of latest executed build on the buildtypeid, for instance the latest one is still running or is queued or it has failed. – Sudheej Jun 25 '17 at 16:40
  • This does not work with TeamCity 2017.1.3 (build 46961). I also tried with passing the api version like this: `httpAuth/app/rest/9.1/` with no luck! – hfm May 29 '18 at 12:38
5

You can get the id of the last successful build by executing the following request:

/httpAuth/app/rest/buildTypes/BUILDTYPE/builds/status:success/id

Then you can query the build itself:

/httpAuth/app/rest/builds/?locator=buildType:BUILDTYPE,id:BUILD_ID
Oleg Rybak
  • 1,651
  • 1
  • 14
  • 27
  • It seems the first request you've given is not supported: `Error has occurred during request processing (Not Acceptable).` – HEADLESS_0NE Mar 28 '16 at 20:37
  • I have tested it on our [public server](https://teamcity.jetbrains.com/httpAuth/app/rest/buildTypes/TeamCityPluginsByJetBrains_VisualStudioOnlineIssueTrackin_TeamCityVsOnlineWork_3/builds/status:success/id). If the error persists, would you mind filing an issue in [the bug tracker](https://youtrack.jetbrains.com) ? – Oleg Rybak Mar 28 '16 at 20:45
  • What TeamCity version are you on? :) – HEADLESS_0NE Mar 28 '16 at 20:46
  • How do we get the status of latest executed build on the buildtypeid, for instance the latest one is still running or is queued or it has failed. – Sudheej Jun 25 '17 at 16:39
0
curl http://username:password@ipofserver:8111/app/rest/builds\?buildType\=BUILDTYPE\&count\=1 --header "Accept: application/json"

Use this in zsh will work, it's already escaped special words with '\'

River Yang
  • 23
  • 5