Two notes to start with:
- I would like to thanks Guy Mazuz that helped me with Teamcity configuration.
- The post was also published on my personal blog.
With SVN life was easy. We used Intellij IDEA with Teamcity for CI so it supports pre-tested commits.
It works as follows: instead of directly commit to trunk, there is a button in intellij IDEA “Run remote…” that essentially sends a patch to Teamcity to run all integration tests and when all tests pass it reports back to IDEA, that in turn commits the tested files directly to trunk (==master).
What it gives you? a higher certainty that your change hasn’t broken anything. As the team gets bigger (and in outbrain we had more than 100 developers committing to trunk) it becomes essential to have such a gatekeeper that will prevent commits that break the trunk. Otherwise, it becomes tedious to keep the trunk green all the time.
When hitting the same button with GIT there is a small asterisk says: “Pre-tested commits are not supported in distributed VCS”. It still puzzles me why it can’t just send a patch with the exact same flow?! Anyway, we wanted this when moving to GIT so we had to find a solution.
Firstly, we could work with pull requests / dev branches / feature branches. That is a viable solution but it makes development speed slower and requires more clicks and time to get to production (ie: more bureaucracy).
The obvious solution was to commit directly to master without testing first in CI server. Since we were in a small team at the time that was actually the first approach we have taken. It works quite well but does not scale well to big teams.
Another viable alternative is to send a patch to Teamcity for testing, and after the tests pass manually approve the files commit and push. Usually, when I commit/push code I love to take a coffee break or something, while this approach forces me to wait until all tests pass.
Finally, we took the auto-merge approach: https://confluence.jetbrains.com/display/TCD9/Automatic+Merge
It took a while to configure but eventually, that worked for us (see how to configure it below).
One notable advantage over the SVN approach is that the workstation doesn’t have to be connected to the network to make the actual approval of the merge while in SVN the commit happens from the IDEA itself.
However, there are some caveats. Most notably, this process has more complicated merges that result in more merge commits. It makes the commit tree a bit more obscure and trashed with merges.
How to configure?
We created a development branch on the server for each developer, myn is dev-oshai. On local repo developers works on master as usual and pull from master. Push is made always to the developer branch. Teamcity, in turn, run all integration tests and auto-merge to master when all tests pass.
In Project configuration settings -> Build features add “Automatic merge”. For some obscure reason, the branch to watch should be defined as “+:oshai”. Not sure why…
Note those branches must be configured also as build triggers, otherwise build will not run at all.
Eventually, Teamcity will show all those branches in the branches view:
Configure Intellij IDEA
Actually here there is not too much to configure. When pushing the code, specify the dev-<you-name> branch itself:
Push from the command line
There are 2 alternatives here:
The simple one is to push like that:
git push origin dev-oshai
In case you would like to use git push(without the branch), it is also possible. See here how to configure it: