In TeamCity you can adjust the conditions when a build should be marked as failed.
To do so, in the Fail build if area specify how TeamCity should fail builds:
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.
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:
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:
<build-metrics> <statisticValue key="myMetric" description="build metric for number of files"/> </build-metrics>
So, if your build will publish value
myMetric, you can use it as a criteria for a build failure.
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:
Note that as well as exact text you can specify a Java Regular Expression regexp pattern to be looked for in build log.