| You are viewing documentation of TeamCity 4.x, which is not the most recent released version of TeamCity. Please refer to the listing to choose another version. |
|
If TeamCity doesn't support your testing framework or build runner out of the box, it is still possible to reap the many of benefits that TeamCity provides by customizing your build scripts to interact with the TeamCity server. This makes a wide range of features available to any team regardless of their testing frameworks and runners. Some of these features include displaying real-time test results and customized statistics, changing the build status, and publishing artifacts before the build is finished. The build script interaction can be implemented by means of:
In this section:
Service MessagesService messages are used to pass commands/build information to TeamCity server from the build script. In order to be processed by TeamCity they should be printed into standard output stream of the build (otherwise, if the output is not in the service message syntax, it should appear in the build log). Service messages support two formats:
Multiple attributes message can more formally be described as: ##teamcity[messageNameWSPpropertyNameOWSP=OWSP'value'WSPpropertyName_IDOWSP=OWSP'value'...OWSP] here:
For escaped values, TeamCity uses a vertical bar "|" as an escape character. In order to have certain characters properly interpreted by the TeamCity server they must be preceded by a vertical bar.
will be displayed in TeamCity as 'foo's test'. Please, refer to the table of the escaped values below.
Common PropertiesAny "message and multiple attribute" message supports the following list of optional attributes: timestamp, flowId. Message Creation TimestampTimestamp format is "yyyy-MM-dd'T'HH:mm:ss.SSSZ" or "yyyy-MM-dd'T'HH:mm:ss.SSS", according to Java SimpleDateFormat syntax e.g. Message FlowIdThe flowId is a unique identifier of the messages flow in a build. Flow tracking is necessary for example to distinguish separate processes running in parallel. The identifier is a string that should be unique in the scope of individual build. Blocks of Service MessagesBlocks are used to group several messages in the build log. Block opening: Block closing:
Reporting Messages For Build LogYou can report messages for build log in the following way: where:
This message fails the build in case its status is ERROR and "Fail build if an error message is logged by build runner" checkbox is checked on build configuration general settings page. For example: Reporting TestsAs TeamCity reports tests results on-the-fly, every testing framework needs its own support for this feature to work. If TeamCity doesn't support your testing framework or build runner, it is possible to modify your build script to send this information to the TeamCity server using service messages that are sent via the standard output of the build process. This makes it possible to display test results in real-time, make test information available on the Tests tab of the Build Results page, and publish artifacts while the build is still in progress. Here is the list of supported test service messages: Test suite messages: All the individual test messages should appear between testSuiteStarted and testSuitFinished (in that order) with the same name attributes. TeamCity 3.x used testSuite* messages only for grouping of the messages in the build log. Starting from 4.x, the test suite is included in the full test name. Individual test messages: Indicates that the test "testname" was run. If testFailed message is not present, the test is regarded as successful. duration attribute is optional. If omitted, the test duration will be calculated from the messages timestamps. If the timestamps are missing, from the actual time the message was received on the server. All the other test messages with the same name attribute should appear between the testStarted and testFinished (in that order).
Optional captureStandardOutput boolean attribute can be present in the testStarted service message to identify whether to include output received between testStarted and testFinished messages as test output or not. The default value is false. If true standard output is reported as test output and standard error as test error output. Indicates that the test "testname" is present but was not run (was ignored). For an ignored test, report the testIgnored message between corresponding testStarted and testFinished messages. Test output reporting (to be shown as the test result if the test fails). A test should have no more then one testStdOut and one testStdErr message. The messages should appear inside testStarted and testFinished messages with the matching name attributes. Indicates that the test with the name "testname" has failed. Only one testFailed messages should appear for a given test name.
Publishing Artifacts while the Build is Still in ProgressAnother cool feature of service messages is that now you can publish build artifacts, while the build is still running. And the files matching the <path> will be uploaded and visible as artifacts of the running build.
Artifacts that are specified in the build configuration setting will be published as usual. Reporting Build ProgressYou can use special progress messages to mark long-running parts in a build script. These messages will be shown on the projects dashboard for corresponding build and on the build results page. To log single progress message use: This progress message will be shown until another progress message occurs or until next target starts (in case of Ant builds). If you wish to show progress message for a part of a build only you can use:
Reporting Build StatusTeamCity allows user to change the build status directly from the build script. You can also permanently change the build status text for your build. Unlike with progress messages, this change persists even after build has finished. To set the status and/or change the text of the build status (for example, note the number of failed tests if the test framework is not supported by TeamCity), use the buildStatus message with the following format: where:
Reporting Build NumberTo set a custom build number directly, specify a buildNumber message using the following format: In the <new build number> value, you can use the {build.number} substitution to use the current build number automatically generated by TeamCity. For example: Reporting Build StatisticsIn TeamCity, it is possible to configure a build script to report statistical data and then display the charts based on the data. Please refer to Custom Chart for a guide to displaying the charts on the web UI. This section describes how to report the statistical data from the build script via service messages. You can publish the build statics values in two ways:
To report build statistics using service messages:
The key should not be equal to any of predefined keys. Reporting FxCop Inspection ResultsTeamCity allows to import FxCop inspections results as an XML-file generated by FxCopCmd tool using the importData message. teamcity-info.xmlIt is also possible to have the build script collect information, generate an XML file called teamcity-info.xml in the root build directory. When the build finishes, this file will automatically be uploaded as a build artifact and processed by the TeamCity server. Modifying the Build StatusTeamCity has the ability to change the build status directly from the build script. You can set the status (build failure or success) and change the text of the build status (for example, note the number of failed tests if the test framework is not supported by TeamCity). XML schema for teamcity-info.xml It is possible to set the following information for the build:
Example teamcity-info.xml file:
Reporting Custom StatisticsIt is possible to provide custom charts in TeamCity. Your build can provide data for such graphs using teamcity-info.xml file. Providing data using the teamcity-info.xml fileThis file should be created by the build in the root directory of the build. You can publish multiple statistics (see the details on the data format below) and create separate charts for each set of values. The teamcity-info.xml file should contain code in the following format (you can combine various data in the teamcity-info.xml file): The key should not be equal to any of predefined keys. The key here relates to the key of valueType tag used when describing the chart. Describing custom chartsSee Custom Chart page for detailed description. |