12
votes

I'm using TeamCity 2017.1.4 along with GitVersion.

The teamcity project itself consists of many build configurations the first of which is to run GitVersion and then all subsequent steps take a snapshot dependency on this step and pull the version from its parameters.

In most scenarios this works great, however if we create a new branch eg. /release-foo and push this, teamcity will not trigger a build because its already previously built the commit sha, unfortunately we need it to trigger again as even though the commit hasn't changed being in a new branch means it will get a different GitVersion number.

I've tried forcing the snapshot dependencies on the GitVersion build configuration to always be rebuilt but this seems kind of ugly as kind of breaks all other scenarios where this isn't a problem. I also know I could manually trigger the build telling it to rebuild all dependencies and it would work, however I'm curious if there's a nicer way to get teamcity to automatically trigger a build for a commit on a branch if that branch didn't previously exist, or indeed any other way I could approach this.

3
I don't agree with the statement "as even though the commit hasn't changed being in a new branch means it will get a different GitVersion number". If you are creating a new branch in Git baselined on a certain commit, then the new branch would use the old Commit # and not have a new one. That is the only way for Git to know where a particular branch was based on.Nishit
i wasnt referring to the git commit sha but the GitVersion number generated by the GitVersion applicationDaniel Powell
After a bit more research it seems like this might be a bug in teamcity or at least in some way related to the settings teamcity.buildRevisions.detectUnknownCommitMerge=true teamcity.vcsTrigger.runBuildOnSameRevisionInEveryBranch=trueDaniel Powell

3 Answers

1
votes

You could try configuring TeamCity to include different/more GitVersion version variables in the build, including the branch name and possibly version tags. This would provide a way for your build process to differentiate between the same commit on different branches.

See steps 1-5 of this CD post, as well as this detailed blog post on using GitVersionTask for some examples on how to use the additional info in TeamCity.

1
votes

You can achieve this by triggering the build from a git hook.

As explained here, you can use a the update hook to identify pushed branches (even when several are pushed in a single operation) and for each branch (assuming it passes your triggering rules) trigger a TeamCity build using the REST API.

0
votes

If you simply amend the commit on the new branch without modifying anything, it will get a new hash because of timestamp changes. I wouldn't consider this a nice solution, but imho it's better than triggering manually.