Get branch information for SVcsModification Follow
In a plugin we are trying to determine the changes which are contained in a build and figured out that
final List<SVcsModification> modifications = runningBuild.getChanges( SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD, false );
for ( final SVcsModification modification : modifications ) {
allows you to iterate over the modifications contained in the build since the last successful one. But what we are interested in are only the changes since the last successful build which are on a specific branch. The reason here is that e.g. a feature branch gets created from the develop and maybe the last build on develop (which is the default branch) was not successful. In this case the changes on develop prior to the branching point are not interesting.
Is there any way to achieve this and determine which branch a modification belongs to?
Thanks,
Hanno
Please sign in to leave a comment.
Hi,
there is no method for that out of the box, but I believe you can achieve what you want using so called BuildPromotion (every build has one, you can get it using the getBuildPromotion() method [1]. Having a build promotion you can call getPreviousBuildPromotion() [2] with same policy as for computing changes. If the previous promotion has different branch [3], then you can iterate though builds, until you reach the default branch.
Code may look like this:
You can also analyze a commit graph using non-open API [4] which can be changed or removed between TeamCity versions. In this case code may look like this (it assumes that the build configuration has only 1 VCS root and that VCS provides information about commit graph, e.g. it is git or mercurial):
[1] http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/BuildPromotionOwner.html#getBuildPromotion() method
[2] http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/BuildPromotion.html#getPreviousBuildPromotion(jetbrains.buildServer.vcs.SelectPrevBuildPolicy)
[3] http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/BuildPromotion.html#getBranch()
[4] http://download.jetbrains.com/teamcity-repository/org/jetbrains/teamcity/internal/server/2017.1/