Unable to render embedded object: File (TeamCity48.png) not found.

TeamCity 9.x Documentation

Documentation for Previous Versions


You are viewing the documentation of TeamCity 9.x, which is not the most recently released version of TeamCity.
View this page in the latest documentation or refer to the listing to choose the documentation corresponding to your TeamCity version.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

In TeamCity you can adjust the conditions when a build should be marked as failed.

Common build failure conditions

To do so, in the Fail build if area specify how TeamCity should fail builds:

  • build process exit code is not zero: Check this option to mark the build as failed if the build process doesn't exit successfully.
  • at least one test failed: Check this option to mark the build as failed if the build fails at least one test. If this option is not checked, the build can be marked successful even if it fails to pass a number of tests. Regardless of this option, TeamCity will run all build steps.
  • an error message is logged by build runner: Check this option to mark the build as failed if the build runner reports an error while building.
  • it runs longer than ... minutes: Check this option and enter a value in minutes to enable time control on the build. If the specified amount of time is exceeded, the build is automatically canceled. This option helps to deal with builds that hang and maintains agent efficiency.
  • an out of memory or crash is detected (Java only): Check this option to mark the build as failed if a crash of the JVM is detected, or Java out of memory problems. If possible, TeamCity will upload crash logs and memory dumps as artifacts for such builds.

Advanced build failure conditions

Starting from TeamCity 7.0 you can instruct TeamCity to mark a build as failed if it has become "worse" by some of the metrics generated by the build, for example, code coverage, or artifacts size, etc. For instance, you can mark build as failed if code coverage or code duplicates number is worse than in the previous build. Another advanced build failure condition allows to mark build as fail when a certain line is met in build log.
To add such build failure condition to your build configuration click the Add build failure condition link and select it from the list:


You can disable a build failure condition temporarily or permanently at any time, even if it is inherited from a build configuration template.

Fail build on metric change

When using code examining tools in your build, like code coverage, duplicates finders, inspections and so on, your build generates various numeric metrics. For these metrics you can specify a threshold which will fail the build upon exceeding them. For example, you can instruct TeamCity to mark build as failed, if code coverage or code duplicates number is worse than in the previous build.

In general there are two ways to configure this build fail condition:

  • A build metric exceeds or is less than the specified threshold. For example: Fail build if build duration (secs) is more than 3000.
  • A build metric has become "worse" comparing to specific build by specified value. For example: Fail build if build duration (secs) is more than 300 compared to Last successful build. In this case a build will fail if it runs 300 seconds longer than the last successful build.

To compare a build metric to, you can select last successful build, last pinned build, last finished build, build with specified build number, last finished build with specified tag.

By default, TeamCity provides the wide range of build metrics: artifacts size(bytes), build duration (secs), number of classes, number of code duplicates, number of covered classes, number of covered lines, number of covered methods, number of failed tests, number of ignored tests, number of inspection errors, number of inspection warnings, number of lines of code, number of methods, number of tests, percent of block-level coverage, percent of class-level coverage, percent of line-level coverage, percent of method-level coverage, test duration (secs).

Moreover you can add your own build metric. To do so, you need to modify TeamCity's configuration file <TeamCity Data Directory>/config/main-config.xml and add the following section there:

So, if your build will publish value myMetric, you can use it as a criteria for a build failure.

Fail build on specific text in build log

TeamCity can inspect all lines in build log for some particular text occurrence that indicates build failure.
Lines are matched fair without time and block name prefixes which precede each message in build log representation.

To configure this build failure condition you need to specify:

  • a string which presence/absence in build log is an indicator of build failure,
  • a failure message to be displayed on build results page when build fails due to this condition.

Note that as well as exact text you can specify a Java Regular Expression regexp pattern to be looked for in build log.

  • No labels