Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent TeamCity building on fast-forward merge to master if build exists for that SHA1

Using TeamCity in combiniation with git.
Currently, TeamCity is set up with "master" as the default branch.

Typically, development takes place on another branch (e.g. "dev") - TeamCity is set to watch for changes on "dev" and build automatically.

If DEADBEEF-SOME-SHA has been built & tagged by TeamCity as build 1.2.3.4 on "dev" and we fast-forward merge that git SHA1 to "master", TeamCity still performs a build - so we end up with DEADBEEF-SOME-SHA being tagged as both 1.2.3.4 and 1.2.3.5.

As I understand it, making "dev" the default branch would prevent this.
Is there another way to prevent TeamCity performing a build if a build has already succeeded for that same SHA1?

Note if we push directly to master (and that SHA1 doesn't exist on other branches / hasn't been built) I'd still like to see a build.

I'd like to achieve this entirely in TeamCity if possible - no additional scripts/writing of files etc etc.

like image 697
eddiewould Avatar asked Oct 19 '17 09:10

eddiewould


2 Answers

If you simply wish to restrict the branches for which builds are automatically triggered, set a branch filter for the VCS trigger:

Project settings => Triggers => VCS Trigger (edit) => Branch Filter

Set the branch filter to

+:dev 

then (even though "master" is the default branch) builds will only be automatically triggered on dev. It is still possible to perform ad-hoc builds on other branches (assuming the VCS root allows it)

like image 51
eddiewould Avatar answered Sep 23 '22 21:09

eddiewould


You can query builds for a particular SHA1... but you have to know your previous buildID for that.

So what I would do is:

  • write in a dedicated folder (accessible by all agents) the sha1 built at the end of each job
  • only triggers a new job if that sha1 file is not already present.
like image 37
VonC Avatar answered Sep 19 '22 21:09

VonC