Blogroll Features How-To's

Building Go programs in TeamCity

TeamCity provides support for multiple technologies and programming languages. In TeamCity 2019.1, support for Go has been included in the distribution. In this blog post, we will explain how to configure TeamCity to work with Go programs.

To enable Go support in TeamCity, go to Build Configuration Settings | Build Features, click Add build feature, and select Golang from the list.

The Golang build feature enables the real-time reporting and history of Go test results in TeamCity.


Running Go tests

Once the Goland build feature is enabled, TeamCity will parse the JSON output of go test command. Hence, the command should be executed with a -json flag using one of these two methods:

  • Add this flag to the Command Line build runner’s script: go test -json
  • Add the env.GOFLAGS=-json parameter to the build configuration


In fact, since a lot of Go projects are actually using make to build the code and execute the tests, it will require changing the Makefile respectively:

    go test -json ./... ; exit 0

The build feature is enabled and a -json argument is added to the go test command. We can now execute the build configuration. As a result, TeamCity will record data about the test execution status, execution time and present this data in the UI.


For each individual test, it is possible to review its execution time from a historical perspective across different build agents where the test was executed.

Muting the failing tests

Assume that there are 248 tests in our project and 4 of those tests are failing. Meaning, the build does not succeed. However, we know that it is okay for those tests to fail and we would like to temporarily “mute” the specific test failures in the project. TeamCity provides a way to “mute” any of the currently failing tests so they will not affect the build status for future builds.


Muting test failures is a privilege of the project administrator. Select the individual failed tests in the build results and click the Investigate/Mute button that appears at the bottom of the screen. It is then possible to mute the tests either project-wide or just in the selected build configuration. The unmute policy can also be specified. For instance, once the test is fixed, it will automatically unmute.


But what does muting the test failure has to do with running Go tests? We use the go test command to execute the tests, and its exit code depends on the status of the execution. If there is even a single test failure, the exit code will be 1. The build will fail since the Command Line build step in TeamCity aims to respect the exit codes.

To mitigate this issue, we just have to make sure that the exit code of the last command in the Command Line runner (or a build script) is 0. For instance, by executing an exit 0 command in the build step (or in the Makefile). In this case, it will be possible to mute the failures and make the build configuration succeed. If the exit code is 0 but there are still test failures that are not muted, then TeamCity knows that it has to fail the build.


Support for Go is provided by TeamCity out of the box, there are no external plugins required. TeamCity parses results of go test command execution. The results are persisted and it is possible to review the figures in a historical perspective. Consequently, all the TeamCity features that are related to test reporting are now available for Go developers.


Comments below can no longer be edited.

3 Responses to Building Go programs in TeamCity

  1. Avatar

    Eric Hubbard says:

    August 7, 2019

    How do you deal with tests printing output that gets intermixed with the json produced by -json? For example if a test prints out something without ending in a \n and now you have a single line of output from go test that contains both json test results & unit test output..

    Maybe you regex each line looking for valid json documents that represent the test results..hmm..

    • Avatar

      Anton Arhipov says:

      August 21, 2019


      The current implementation doesn’t use regexp to search for JSON in the output. The code checks for the ‘{‘ ‘}’ characters at the start and at the end of the line. So if the line matches then the contents will be parsed for the data.

      If there’s a print statement in your test without “\n” then we wouldn’t be able to locate a valid json. Golang devs recommend using t.Log / t. Error instead of print calls for logging the output in the tests.

  2. Avatar

    Tobias Grieger says:

    December 2, 2019

    Hi folks,

    I noticed that after setting this up, tests which don’t start with `Test` don’t get parsed any more. This includes notably benchmarks as well as a custom test runner we have (whose tests have a different naming scheme).

    Is this behavior reasonable? IMO if the JSON output gives you a test you should parse it, regardless of the name. Right now I’m forced into awkward workarounds (that in turn break other parts of our tooling that expect the real name).


Discover more