How do I get the vcs changes since last successful build?

I'm trying to get the same results from the REST api as I would from the UI:

Currently, I just get the changes for newest build (https://teamcity.local/httpAuth/app/rest/changes?build=id:1234), but I'd like to get all the changes since the last time the build was successful.

Is there a single api call to do this? Or what's the simplest way?

Thanks



Attachment(s):
lqcpt.jpg
5 comments
Comment actions Permalink

John,

An obvious approach is to get the id of the last change in a "since" build you want to use and then issue a request like
.../app/rest/changes?locator=buildType:(id:XXX),sinceChange:(id:YYY)
If you know the "since" build id you can even use
.../app/rest/changes?locator=buildType:(id:XXX),sinceChange:(build:(id:ZZZ))

There is no one request way to find a previous failed build, though. You can get the build's sequence and find the necessary build.

Note: I will look into adding ability to find previous failed build in one request in the future TeamCity versions.

0
Comment actions Permalink

Yet another possible approach:

Since TeamCity 9.0 you can get the list of builds with the change details right away via a request like:
.../app/rest/builds?locator=buildType:(id:XXX)&fields=$long,build(id,number,status,changes($long))

0
Comment actions Permalink

Hi, thanks for replying.

The problem is that there's no good way of knowing the 'sinceChange' id.
It means I have to first query all the builds for the specific build types and determine whether they were successful or not, then run an additional query to get the changes id for the last successful build.
Only then would I be able to run .../app/rest/changes?locator=buildType:(id:XXX),sinceChange:(id:YYY)
It's pretty big overhead to run so many api calls for the off chance a build might fail.

Is there a faster way to do this I'm not thinking of?

0
Comment actions Permalink

John,

Looking into this more: it seems that it is actually possible to get changes since "last successful" build till the current moment in a single request.

Basically the request
.../app/rest/builds/buildType:(id:XXX),untilBuild:(id:ZZZ),status:SUCCESS
should give you the previous failed build (before the build with id ZZZ).
And
.../app/rest/changes?locator=buildType:(id:XXX),sinceChange:(build:(buildType:(id:XXX),untilBuild:(id:ZZZ),status:SUCCESS))
gives you all the changes since that build.

Still, my second suggestion to get list of builds with the changes included might be better: you just need to iterate through the builds and the changes are already there.

0
Comment actions Permalink

I also would like to get all the changes since last successful build.

I'm using TC version 9.x and the following api calls that were recommended here didn't work for me.

../app/rest/changes?locator=buildType:(id:XXX),sinceChange:(build:(id:ZZZ))

.../app/rest/changes?locator=buildType:(id:XXX),sinceChange:(build:(buildType:(id:XXX),untilBuild:(id:ZZZ),status:SUCCESS))

In fact the only way I was able to use 'sinceChange' was by 'change id'. Is there a way to apply 'sinceChange' using build id?

 

Many thanks

0

Please sign in to leave a comment.