Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity Trigger on Pull Request vs Trigger on Merge

We build features in GitHub branches (one feature branch to one feature). We have a develop branch and a master branch. Both should always be green.

We use TeamCity for builds and deploys. What I want to get to is that when a pull request is created (from the feature branch to develop), TeamCity automatically builds and tests the request, then boots up an EC2 instance so that it can be manually tested. When the pull request is then merged, TeamCity builds, tests and creates a docker image which we push out onto ECS.

This all works, except we have the triggering wrong.

1) For building the pull request, the VCS root has a default branch set as develop and has a branch specification of +:refs/pull/(*/merge) - we don't want to solely build the pull request but build the merged code. We then deploy this out onto an EC2 instance for manual testing.

2) TeamCity reports the status of building the pull request to GitHub and, after manual testing using the EC2 instance, the code is merged from the feature branch into develop. At this point, we want to build the code in develop and then we push out the new micro-service onto the Amazon ECS. For building once the pull request is merged into develop, the VCS root has a default branch set as develop.

In reality, 1 is always triggered e.g. for both raising a pull request and the merge into develop. 2 is triggered only when the merge into develop occurs which is correct.

Any help would be greatly appreciated.

EDIT

I've clarified the two build configurations we use above

like image 536
christophmccann Avatar asked Oct 19 '22 05:10

christophmccann


1 Answers

According to the documentation, if you only want to only build the merged code of your pull request, you don't need to specify the parenthesis.

https://blog.jetbrains.com/teamcity/2013/02/automatically-building-pull-requests-from-github-with-teamcity/

Now, (...) see whether the particular request was the result of a merge or just the branch itself. For that, we can specify the following in the Branch Specification

+:refs/pull/(*/merge)

Once the pull request created, TeamCity will only test the result of the merged code into develop.

Using the TeamCity automatic merge feature (included in TC9), a new commit will be triggered on the develop branch, which will run your configuration (build on develop, tests on develop, deploy...) properly

So, you might just have to replace your branch specification from: +:refs/pull/(*/merge) to +:refs/pull/*/merge

like image 87
Didier Aupest Avatar answered Oct 21 '22 06:10

Didier Aupest