3
votes

I'm using GitLab 8.3.2 and TeamCity 9.1.6. I've set up the JetBrains TeamCity CI service and it is triggering builds in TeamCity when changes are pushed to GitLab.

I'd like it to also trigger a build when a merge request is created (my understanding is that this build could guarantee that hitting the merge button will not break things).

I've got the branch specification in TeamCity set to:

+:refs/heads/*
+:refs/(merge-requests/*)

I can see the merge requests in TeamCity, but they don't actually build.

The merge request in GitLab says 'CI build pending for xxxx'. The view details link does not contain a build number though. I suspect this is because it searches TeamCity to find a matching build and doesn't find it because it wasn't triggered in the 1st place.

I do not have any build triggers configured in TeamCity. (I did originally have a VCS trigger, but I turned it off once I realised that GitLab was triggering builds for me.)

How can I set things up so that a merge request triggers a build in TeamCity and have GitLab display the result of the build in the merge request.

2

2 Answers

5
votes

You should decide how you want the builds to be triggered: by TeamCity which will poll GitLab for updates or by GitLab.

For TeamCity way you will need to add a VCS trigger into the build configuration. This will make TeamCity trigger builds on the branches configured in "branch specification". You can also limit the branches to trigger builds for in the trigger settings. You will need to disable GitLab triggering builds in TeamCity.

For GitLab way to trigger builds in all branches you might need to set branch specification to

+:(refs/heads/*)
+:(refs/merge-requests/*)

to make sure the branches are full named (I am guessing here).

0
votes

I manage to solve my issue that is similar to you. Actually, I follow the instruction provided by GitLab

The build configuration in Teamcity must use the build format number %build.vcs.number% you will also want to configure monitoring of all branches so merge requests build, that setting is in the vsc root advanced settings.

  1. in Teamcity's side, you need to set build number format as %build.vcs.number%
  2. configure Branch specification in Teamcity to build all branches. I've used +:refs/heads/(*) for my case.

After merge request is created, it'll check the same build.vcs.number in teamcity and when the build is finished, the status will be updated in gitlab's merge request