Search code examples
.netgithubteamcity-8.0

How to make TeamCity only deploy builds for the default branch?


Our TeamCity process basically involves 3 "Build Configurations" that run in sequence:

  1. Build Step, triggered by source control (in our case GitHub): MSBuild builds everything, and creates one artifact containing all the unit test binaries, and several deployment package artifacts, one per website in the Visual Studio solution.
  2. Unit Test Step, triggered by the success of Step 1. This picks up the unit test binaries artifact and runs the unit tests.
  3. Deployment Steps, triggered by the success of Step 2. These each pick up the relevant deployment package artifacts and deploy them.

I've recently amended Step 1 to also pick up changes from Pull Request branches on GitHub, so that the Pull Request can be updated with the build result. I want to also run the Unit Tests for each Pull Request, but obviously not do any deploys in these cases.

So Step 1 has a Branch Filter to match the default branch or Pull Request branches. I can update the Trigger in Step 2 to also have this Branch Filter. However, the Triggers in the Deployment Steps do not have the option of a Branch Filter.

How can I only run the Deployment Steps for builds from the default branch?


Solution

  • My solution to this was to create a new Build Configuration solely for Pull Requests; this contains build steps to do the compilation and run the unit tests.