| You are viewing documentation of TeamCity 6.5.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, you can still avail yourself of many TeamCity benefits 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.
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). A single service message should not contain a newline character inside it, it should not span across multiple lines. Service messages support two formats:
Multiple attributes message can more formally be described as: ##teamcity[messageNameWSPpropertyNameOWSP=OWSP'value'WSPpropertyName_IDOWSP=OWSP'value'...OWSP] where:
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 Compilation Messageswhere:
Reporting TestsTo use TeamCity's on-the-fly test reporting, testing framework needs dedicated support for this feature to work (alternatively, XML Report Processing can be used). 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. Test start/stop messages: Indicates that the test "testname" was run. If testFailed message is not present, the test is regarded as successful. duration (optional numeric attribute) - sets the test duration to be reported in TeamCity UI. If omitted, the test duration will be calculated from the messages timestamps. If the timestamps are missing, from the actual time the messages were received on the server.
It is highly recommended to ensure that the pair of test suite + test name is unique within the build. Ignored tests: Indicates that the test "testname" is present but was not run (was ignored) by the testing framework. Test output: testStdOut and testStdOrr service messages report the test's standard and error output to be displayed in TeamCity UI. There should be no more then single testStdOut and single testStdErr message per test. Test result: Indicates that the test with the name "testname" has failed. Only single testFailed message should appear for a given test name. Here is a longer example of test reporting with service messages: Reporting .NET Code Coverage ResultsYou can configure .NET coverage processing by means of service messages. To learn more, refer to Manually Configuring Reporting Coverage page. Publishing Artifacts while the Build is Still in ProgressYou can publish build artifacts, while the build is still running, right after the artifacts are built. And the files matching the <path> will be uploaded and visible as artifacts of the running build. <path> should adhere to the same rules as Build Artifact specification on the Build Configuration settings.
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: Adding or Changing a Build Parameter from a Build StepBy using dedicated service message in your build script, you can dynamically update some build parameters right from a build step, so that following build steps will run with modified set of build parameters. When specifying a build parameter's name, mind the prefix:
The changed build parameters will also be available in dependent builds as %dep.*% properties. 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 the Customizing Statistics Charts#customCharts page 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. Disabling Service Messages ProcessingIf you need for some reason to disable searching for service messages in output, you can disable service messages search with the messages: Any messages that appear between these two are not parsed as service messages and are effectively ignored. Importing XML ReportsIf you prefer to run code coverage, code inspection, test tools or duplicate finders directly from build script, not as a build runner, you can use the importData service messages to import generated xml reports into TeamCity. where sometype can be one of the following:
For the report types above you can also use wildcards to specify the path.
To initiate monitoring several directories or parse several types of the report, send the corresponding service messages one after another. Note, that when using this service message to import .NET coverage results you need also specify which tool you use to generate reports: where tool name can be dotcover, partcover, ncover or ncover3.
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 Customizing Statistics Charts page for detailed description. |