4

I'm looking for Code Coverage on Jenkins. Unfortunately I need coverage for C# projects.

What I've tried until now: I'm using dotCover (over commandline) to create either html results or xml results (it's working). I tried to use "cobertura" plugin to view the xml results (it's not working, I know, I need different xml format). I can't use only cobertura for the projects, because there are only freestyle projects and no ant/maven projects.

So is there any possibility to use dotCover results (xml/html/json) to convert to an xml format so cobertura (or any other plugin) thinks it is an actual "maven/ant" project?

Or is there any other plugin for C# CodeCoverage projects to report in Jenkins?

I'm new at this, so sorry if the question is too simple.. =) Cheers

Lino556
  • 133
  • 1
  • 9
  • I also tried to embed the html result to each build. But it's very tricky and the "java script" part is not working properly. – Lino556 Feb 18 '16 at 07:37

1 Answers1

3

You can parse and evaluate the dotcover result by a powershell script in Jenkins (this needs Powershell Plugin to be installed):

Example of parsing HTML result by Powershell

#Command line arguments: 
#0: File name of the HTML coverage report generated by dotCover
[string]$path = $args[0]
#1: Expected coverage threshold
[int]$threshold = $args[1]

#Retrieving total coverage percentage from HTML coverage report
$pattern = '^.*\[\[\"Total\",(\d+),.*$'
$report = Get-Content $path
$line = $report -match $pattern
$value = $line -replace $pattern, '$1'
[int]$coverage = [convert]::ToInt32($value, 10)

#Comparing coverage with threshold
Write-Host checking coverage threshold: $threshold
if ($coverage -ge $threshold) {  
    Write-Host passed with percent $coverage
    return 0
}
else { 
    Write-Host failed with percent $coverage
    return -1 
}

If you are using HTML result, it is also possible to publish the coverage result using the HTML Publisher plugin

Publish HTML result

K.Roland
  • 128
  • 1
  • 8