Skip to content

Teamcity service not finding build ID

I am trying to set up the Teamcity service for one of my projects. The problem I am having is that it doesn't seem to find the build ID in the Merge Requests. As the instructions say, I've set the Teamcity build number format to use the vcs number.

image

And the builds looks correct in TeamCity:

image

However the merge requests in Gitlab don't seem to be finding the builds and look like this:

image

And the URL for the build details does not include the build ID.

https://tc.imsweb.com//viewLog.html?buildTypeId=SeerApi_Build

The code for finding the correct build ID is in

https://gitlab.com/gitlab-org/gitlab-ee/blob/1fa19401e969f79cbd737c55e63249ca9355791c/app/models/project_services/teamcity_service.rb

In particular:

  def build_info(sha)
    url = URI.parse("#{teamcity_url}/httpAuth/app/rest/builds/"\
                    "branch:unspecified:any,number:#{sha}")
    auth = {
      username: username,
      password: password,
    }
    @response = HTTParty.get("#{url}", verify: false, basic_auth: auth)
  end

  def build_page(sha)
    build_info(sha) if @response.nil? || !@response.code

    if @response.code != 200
      # If actual build link can't be determined,
      # send user to build summary page.
      "#{teamcity_url}/viewLog.html?buildTypeId=#{build_type}"
    else
      # If actual build link is available, go to build result page.
      built_id = @response['build']['id']
      "#{teamcity_url}/viewLog.html?buildId=#{built_id}"\
      "&buildTypeId=#{build_type}"
    end
  end

I am assuming the API call if build_info is failing (not returning 200). The build_page method then returns a URL without the buildId in it. That is the behavior I am seeing. However when I manually build the URL and just execute it through the browser it works:

https://tc.imsweb.com/httpAuth/app/rest/builds/branch:unspecified:any,number:1c9e991a0332a72a14bcd7801da4a2c27a953827

This returns a 200 status and all the build information.

Am I doing something wrong, or is this not working?