Get Coverage percentage to TeamCity

Get Coverage percentage to TeamCity

From the TeamCity manual, I can change the status text of the build to include my additional details. Such as

teamcity-info.xml:

<!-- or SUCCESS --> fitnesse: 45 coverage: 54%

I would very much like to do this myself to include NCover result percentage. The trouble is "where do I get this information?". Based on the pasted sample, I should be able to set a property to contain the different coverage percentages and include it in teamcity-info.xml.

Is there some existing way to get this, or can you add some output parameter(s) to the NCoverReporting task I can later use in the script?

Bjørnar Sundsbø


RE: Get Coverage percentage to TeamCity

Bjornar,

Thanks for writing in! I think what you're asking is how to get coverage data pushed into TeamCity after a coverage run that's included as a task in your build...is this correct?

We have written some clear documentation on this very question here: http://docs.ncover.com/how-to/continuous-integration/teamcity/. You should be able to include TeamCity service messages in your NCover task as part of your build script. TeamCity will pick up the coverage report you generate and post it to your results console as a new tab.

I've never done precisely what you're asking in your post--pulling a coverage number from the command line and appending it to the build status. If you're running NCover as a build task in your script, you should see a message from NCover in your log file indicating coverage results. NCover is not yet programmed to interface with custom scripts to capture return coverage values from our code. You can, however, use a custom script to parse the coverage report xml, which we give a definition for here: http://docs.ncover.com/kb/ncover-trend-and-report-file-definition/.

Let me know if this information helps to get you where you want to be.

Thanks!


RE: Get Coverage percentage to TeamCity

David,

Including the reports in TC is not a problem, and has been done for a couple of years now. The trouble is, as you say, append the result to the build status. Such as

Tests passed: 418, ignored: 1 (S75%, B78%, M79%)

That way we can easily see the changes in coverage in the history, and immediately know who to blame :)

Using a script as you suggest will most likely not work, as we will then get the same behavior as we've discussed previously about filters not being regarded (as trend statistics is incorrect when adding a filter to NCoverReport) as the xml file includes information about all the being covered.

I could have parsed the log output from the NCoverReporting task somehow, and get the correct numbers. The trouble is that information is only available on failing builds. Also, it does not include all the information, only unmet requirements when using minimum coverage. New Project (Branch: 75,73% Minimum: 76,00% ) 1 items failed the minimum coverage rules.

Also, failing builds exit with error code 3. I've had a discussion with sporwell in the old forums a few years back about return codes and informative messages being posted to TC :)


RE: Get Coverage percentage to TeamCity

Bjornar,

Thanks for the clarification! We don't yet do what you're asking out of box. It's a good idea. If it's something you need pieced together for your team, the process might look like this:

(1) generate a coverage report, (2) parse the data you want using our open specs, (3) store the data somewhere, (4) on subsequent runs, check that data and compare it.

We're always working on improvements, and so I thank you for your note. I'll look forward to hearing if / how this works for your team. Email me anytime: support@ncover.com.


RE: Get Coverage percentage to TeamCity

Unless there is a coverage file that will regard my filters, I don't think I will take that route. I'll see if I can generate a summary XML report and parse that.

I'll see if my project leader will allow me some time to look into this soon.

Bjørnar


RE: Get Coverage percentage to TeamCity

Seems many of the report types that contains the data I'm interested in does not support XML. I was able to create the SymbolModule as XML, but looking through it, it seems excluded/filtered code and assemblies are also contained in the file. How will that affect the numbers and calculations I extract from the report? Is this where the ReportDataFilter comes into play?

Do you have any samples for Xslt or something similar I can modify?

Bjørnar


RE: Get Coverage percentage to TeamCity

Nevermind, I managed to do it by using some of the information provided in this blog: http://www.paraesthesia.com/archive/2010/05/06/failing-the-build-with-ncover-3.4.x.aspx

I used the first XLST to generate the content of teamcity-info.xml to display the needed information. Then I passed the XSLT to the XsltOverridePath attribute of the NCoverReporting task.


RE: Get Coverage percentage to TeamCity

Awesome! Thanks for sharing that, bsundsbo. Please let us know if you learn any other handy workarounds. This is great! Thanks for using NCover.