TeamCity - Stop build when a test fails
Asked Answered
S

3

8

Is it possible to stop a TeamCity build (the entire build, i.e. it won't execute subsequent steps) when a unit test fails? Ideally I'd also like it to terminate the currently executing step which in my case would be the Nunit Test Runner. In my circumstance there is no point in continuing the build if a single unit test fails. I've looked at Failure Conditions but I don't think they are applicable as the build continues to run.

Feature requested: http://youtrack.jetbrains.com/issue/YTF-3275

Spermatophyte answered 30/7, 2013 at 16:5 Comment(2)
Not exactly what you want, but close: #15255081Nananne
It's close but no cigar, although you have just reminded me that I need to be careful of this. There is a solution, check the last comment of this youtrack.jetbrains.com/issue/TW-17002. This isn't what I want however, I want the step to stop executing when an test fails.Spermatophyte
M
3

You can do it using nunit-console.exe. accordingly to the official documentation (http://nunit.org/index.php?p=consoleCommandLine&r=2.6.2) it provides a /stoponerror switch that does exactly what you need.

it can also generate an XML output that can be parsed by teamcity (there is a build feature for that) in order to populate the "test" tab.

Monzonite answered 30/7, 2013 at 20:43 Comment(3)
This seems like the only way to do this, it's hackish and I don't like it so I've contacted TeamCity to see if I can submit a feature request.Spermatophyte
Is this still the case in 8.0.5? Seems like it should be fixed by now. Is XUnit or MSTest better supported?Cellist
As of TC 2019.1 you can stop the build from your scripts https://mcmap.net/q/782404/-can-i-cancel-a-teamcity-build-from-my-msbuild-scriptConchiferous
R
6

As you noted, TeamCity can run no further build steps on test failures in NUnit tests with "Only if build status is successful" step execution condition. However, that does not make the tests run stop until the step finish.

A related feature request is TW-23766.

The only workaround I can consider currently is not to use NUnit test runner and implement the logic inside the build script. For example, with nunit-console.exe like Manuel noted. If you choose to follow this route, consider using TeamCity Addin for NUNit.

Rios answered 31/7, 2013 at 17:45 Comment(0)
M
3

You can do it using nunit-console.exe. accordingly to the official documentation (http://nunit.org/index.php?p=consoleCommandLine&r=2.6.2) it provides a /stoponerror switch that does exactly what you need.

it can also generate an XML output that can be parsed by teamcity (there is a build feature for that) in order to populate the "test" tab.

Monzonite answered 30/7, 2013 at 20:43 Comment(3)
This seems like the only way to do this, it's hackish and I don't like it so I've contacted TeamCity to see if I can submit a feature request.Spermatophyte
Is this still the case in 8.0.5? Seems like it should be fixed by now. Is XUnit or MSTest better supported?Cellist
As of TC 2019.1 you can stop the build from your scripts https://mcmap.net/q/782404/-can-i-cancel-a-teamcity-build-from-my-msbuild-scriptConchiferous
K
0

on the build step after the unit tests, change the setting to Only if Build status is successful instead of if all previous steps finished successfully

see screenshot

also make sure that under failure conditions menu item the at least one test failed option is also ticked.

enter image description here

Klenk answered 16/9, 2020 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.