In TeamCity you can adjust the conditions when a build should be marked as failed in the Failure Conditions section of the of the Build Configuration Settings page.
On this page:
|Table of Contents|
Common build failure conditions
To do so, In the Common Failure Conditions, specify how TeamCity will fail builds by selecting appropriate options from in the Fail build if area specify how TeamCity should fail builds:
- it runs longer than ... minutes: Check this option and enter a value in minutes to enable execution timeout for 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.
- the 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
Additional Failure Conditions
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, its metrics has deteriorated in comparison with another build,e.g. code coverage, or artifacts size, etc. For instance, you can mark build as failed if the code coverage or code duplicates number is worse higher than in the previous build.
Another advanced build failure condition allows causes TeamCity to mark build as fail failed when a certain line text is met present in the 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, when exceeded, will fail the a 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:
The following builds can be used as the basis for comparing build metics:
- 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
- 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 passed tests
- number of tests
- percentage of block coverage
- percentage of class coverage
- percentage of line coverage
- percentage of method coverage
- percentage of statement coverage
- test duration (secs)
- total artifacts size (bytes)
Note that since TeamCity 9.Moreover you 0, the way TeamCity counts tests has changed.
Adding custom build metric
You can add your own build metric. To do so, you need to modify the TeamCity 's configuration file
TeamCity Data Directory
>/config/main-config.xml and add the following section under "server" node there:
<build-metrics> <statisticValue key="myMetric" description="build metric for number of files"/> </build-metrics>
So, if your build will publish publishes the
myMetric, you can use it as a criteria criterion for a build failure.
TeamCity can inspect all lines in build log for some particular text occurrence that indicates a build failure.
Lines are matched fair without the time and block name prefixes which precede each message in the build log representation.
To configure this build failure condition you need to , specify:
- a string which or a Java Regular Expression whose presence/absence in the build log is an indicator of a build failure,
- a failure message to be displayed on the build results page when a 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.