|You are viewing documentation of TeamCity 7.x, which is not the most recently released version of TeamCity. Please refer to the listing to choose another version.|
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:
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.
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.
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
So, if your build will publish value
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.
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.