Having Code Coverage Appear in Build Status Text

My organization would like to add the Code Coverage percentage to the build status label. (Ex: 'Tests failed: 3 (3 new), passed: 1301, ignored: 66; Coverage 76.1%;') This will be a quick way to tell and compare the coverage’s across builds without drilling into the Code Coverage tab or a report. It would add value to the project view screen and makes sense to highlight the coverage. From searching the web and your forums, it appears to be impossible using dotCover integration.

Custom Script Approach

I looked into having an additional build step that is a custom script to set the build status using a command like: ##teamcity[buildStatus status='<status value>' text='{build.status.text}; Coverage($COVERAGE)']". This could be a work-around with an additional script to parse the code results but the problem is the Code Coverage step is not parsed/merged into TeamCity until after all the steps have run in the 'Merge dotCover reports' section. The configurable steps are great but why have dotCover merge section occur NOT as one of those steps (It occurs at the end after all steps -see log-). It should just be another step or occur as part of the UnitTest step not at the end where the results cannot be obtained by any other step. Looking at the log of that dotCover merge it would be very easy for you to have the build status updated when the ##teamcity[buildStatisticValue key='CodeCoverageS' value='71.56627'] command is output to the console. If the dotCover merge plugin was open source I could fix it internally (main reason we are looking into Jenkins as an alternative).

Is there any way to modify the dotCover merge to set the build status?

Build Log:

[09:25:28]Checking for changes

[09:25:29]Publishing internal artifacts

[09:25:29]Clearing temporary directory: C:\BuildAgent\temp\buildTmp

[09:25:29]Checkout directory: C:\inetpub\wwwroot

[09:25:29]Repository sources transferred

[09:25:29]Updating sources: server side checkout

[09:25:29]Step 1/8: Compile (MSBuild) (6s)

[09:25:36]Step 2/8: Build Database (Command Line)

[09:25:37]Step 3/8: Prepare Website (Command Line)

[09:25:37]Step 4/8: Unit Test (NUnit) (2m:46s)

[09:28:23]Step 5/8: Cleanup (Command Line)

[09:28:24]Running Inspections

[09:28:24]Step 6/8: Code Analysis (Inspections (.NET)) (1m:45s)

[09:30:10]Searching for duplicates

[09:30:10]Step 7/8: Code Duplicates (Duplicates finder (.NET)) (15s)

[09:30:26]updating diff...

[09:30:26]Duplicates: 44 (+1 -25)

[09:30:25]Step 8/8: Add Test Coverage to Build Status (Command Line)

[09:30:26]Waiting for 3 service processes to complete

[09:30:26]Processing 1 coverage report(s)

[09:30:26]Generating coverage report by dotcover for files: [C:\BuildAgent\temp\buildTmp\tmpE5FE.tmp]

[09:30:26]Get dotCover version

[09:30:26]DotCover version is 1.2.352.19. This version is newer than TeamCity and may not be fully supported.

[09:30:26]Use DotCover 1.1.x commands set

[09:30:26]Merge dotCover reports (6s)

[09:30:32]Remove dotCover snapshot files

[09:30:33]Generate dotCover report (8s)

[09:30:41]Generate dotCover HTML report

[09:30:41]Packing snapshot files (7s)

[09:30:48]Remove dotCover snapshot files

[09:30:48]DotCover statement coverage was: 594 of 830 ( 71.56627%)

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageS' value='71.56627']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageAbsSCovered' value='594.0']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageAbsSTotal' value='830.0']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageM' value='73.61111']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='53.0']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='72.0']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageC' value='75.0']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageAbsCCovered' value='12.0']

[09:30:48]##teamcity[buildStatisticValue key='CodeCoverageAbsCTotal' value='16.0']

[09:30:48]Publishing artifacts

[09:30:48]Publishing artifacts

[09:30:48]Publishing artifacts

[09:30:48]Publishing internal artifacts

[09:30:48]Publishing artifacts

[09:30:49]Total: 608 (+0 -0) Errors: 182 (+0 -0)

[09:30:49]Build finished

2 comments
Comment actions Permalink

Hello,

Sorry for the delay in replying.

Your description of the issue seems quite accurate: build status text can be changed only from within the build, but coverage numbers are calculated after all build steps are finished.

There seems to be two ways: either write TeamCity Java plugin to update the build status text after the build finish, or get the resultant coverage numbers within the build, not relying on TeamCity covergae features.

You are welcome to file a corresponding feature request into the tracker.

0
Comment actions Permalink

Did you resolve this issue?

1

Please sign in to leave a comment.