TeamCity: How to configure GitLab & Commit Status Publisher to publish build status on merge request

GitLab version: 11.3.5-ee 7b10203
TeamCity version: 2018.1 (build 58245)
Commit Status Publisher version: unknown (likely one packaged with TC)

I’ve read everything I can find on this and I’m still getting a 404 error when “developers” generate a merge request from a forked repo (believe this is the recommended git process for changes). The builds are triggering (I think due to polling, not due to the GitLab Project Service for TC which I configured, due to the time it takes for the build to trigger which is in line with the TeamCity polling interval, not virtually instantaneous as I would expect with the GitLab Project Service).

The Commit Status Publisher is configured in accordance with this documentation: https://confluence.jetbrains.com/display/TCD18/Commit+Status+Publisher. It passes the local test.

In the TeamCity error message from the Commit Status Publisher plug-in, the repo name is encoded but the rest of the URL is not which I find strange but I don’t think this is the problem.

I did find an outstanding pull request on the commit status publisher GitHub repo (from 2016) that sounds like this problem might be a commit status publisher bug but the issue is not described in sufficient detail to be able to tell for sure. Apparently, the PR is not being merged due to legal review.

The merge request documentation for requiring a successful build says it requires a pipeline to be configured but does not give good details on how to do that. Most everything I read seems to relate to GitLab CI/CD, not 3rd party systems.

The TeamCity build agent’s faceless account has “maintainer” rights in GitLab project.

GitLab documentation really needs TLC!

Hey,
In case anybody still got issue with Commit Status Publisher posting successfully on GitLab,
this build feature uses the commit “statuses” request from GitLab’s API using the merge request branch’s commit sha as parameter.

The documentation mentions “If the commit is associated with a merge request, the API call must target the commit in the merge request’s source branch.”.
So when the Commit Status Publisher uses the merge request’s commit itself it gets this error “message”: “404 References for commit Not Found”.

The workaround that did the trick for me was to request the merge-request infos using GitLab’s API in my TeamCity build.

The response features the sha of the source branch’s last commit in the sha property.

Then sending the “statuses” request from my build using this sha updated my merge requests properly.

In my context I couldn’t use the JetBrains TeamCity integration in GitLab FYI. So I don’t know if that helps getting notifications properly.