来自VSTS的SonarQube代码覆盖率

来自VSTS的SonarQube代码覆盖率,sonarqube,azure-devops,code-coverage,Sonarqube,Azure Devops,Code Coverage,我正在使用VSTS托管的代理VS2017来运行构建、测试和分析。我正在使用来自市场()的SonarQube扩展。正在使用的任务版本为4,它使用SonarQube扫描仪进行MSBuild 4.0.2 分析工作得很好,但它不能将代码覆盖率结果转换为SonarQube。我可以在VSTS(构建细节)中看到代码覆盖率分析,但在SonarQube中看不到 据我所知,问题在于VSTS生成一个扩展名为.codecoverage的二进制文件。SonarQube不知道如何处理这个文件。我很难将其转换为XML格式,因

我正在使用VSTS托管的代理VS2017来运行构建、测试和分析。我正在使用来自市场()的SonarQube扩展。正在使用的任务版本为4,它使用SonarQube扫描仪进行MSBuild 4.0.2

分析工作得很好,但它不能将代码覆盖率结果转换为SonarQube。我可以在VSTS(构建细节)中看到代码覆盖率分析,但在SonarQube中看不到

据我所知,问题在于VSTS生成一个扩展名为.codecoverage的二进制文件。SonarQube不知道如何处理这个文件。我很难将其转换为XML格式,因为我似乎没有办法这样做

是否有人成功地将VSTS与SonarQube一起使用,并将代码覆盖率结果发送给SonarQube?你是怎么设置的

编辑1
我使用的SonarQube版本是:6.7版(Build33306),社区版

编辑2
分析结束时实际上会生成xml文件,如下面的注释所述。这来自日志:

2018-03-06T11:14:56.4189055Z 11:14:56.417  Attempting to locate the 
CodeCoverage.exe tool...
2018-03-06T11:14:56.4210147Z 11:14:56.42  Attempting to locate the 
CodeCoverage.exe tool using setup configuration...
2018-03-06T11:14:56.4345085Z 11:14:56.433  Code coverage command line tool: 
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team 
Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
2018-03-06T11:14:56.4349101Z 11:14:56.434  Fetching code coverage report 
information from TFS...
2018-03-06T11:14:56.4363869Z 11:14:56.435  Attempting to locate a test 
results (.trx) file...
2018-03-06T11:14:57.0458245Z 11:14:57.044  Looking for TRX files in: 
D:\a\1\TestResults, D:\a\1\s\TestResults
2018-03-06T11:14:57.0462747Z 11:14:57.045  Located a test results file: 
D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09.trx
2018-03-06T11:14:57.0600587Z 11:14:57.059  One code coverage attachment was 
found in the trx file: factoryvm-az436\VssAdministrator_factoryvm-az436 
2018-03-06 11_11_34.coverage
2018-03-06T11:14:57.0602504Z 11:14:57.059  Absolute path to coverage file: 
D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09\In\factoryvm-az436\VssAdministrator_factoryvm-az436 2018-03-06 
11_11_34.coverage
2018-03-06T11:14:57.0691948Z 11:14:57.068  Executing file C:\Program Files 
(x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code 
Coverage Tools\CodeCoverage.exe
2018-03-06T11:14:57.0692731Z   Args: analyze 
/output:D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09\In\factoryvm-az436\VssAdministrator_factoryvm-az436 2018-03-06 
11_11_34.coveragexml D:\a\1\s\TestResults\VssAdministrator_factoryvm-
az436_2018-03-06_11_13_09\In\factoryvm-az436\VssAdministrator_factoryvm-
az436 2018-03-06 11_11_34.coverage 
2018-03-06T11:14:57.0694963Z   Working directory: 
D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09\In\factoryvm-az436
2018-03-06T11:14:57.0695792Z   Timeout (ms):60000
2018-03-06T11:14:57.0699007Z   Process id: 3540
2018-03-06T11:14:58.7847582Z 11:14:58.783  Process returned exit code 0
2018-03-06T11:14:58.7858908Z 11:14:58.784  Updating project info files with 
code coverage information...

VSTS扩展应该自动导入覆盖率结果,但目前有一个回归很快就会得到修复(希望如此):

同时,在
附加属性
文本区域中,添加以下属性:

sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml

即使设置了“sonar.verbose=true”、“system.debug=true”,我也无法查看“coveragexml”文件。尽管如此,我找到了另一种工作正常的方法,即使用PowerShell脚本将“.coverage”文件转换为“.coveragexml”:

Get-ChildItem -Path $(Agent.TempDirectory) -Include "*.coverage" -File -Recurse | % {
$outfile = "$([System.IO.Path]::GetFileNameWithoutExtension($_.FullName)).coveragexml"
$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($_.FullName), $outfile)
"Analyse '$($_.Name)' with output '$outfile'..."
.$env:USERPROFILE\.nuget\packages\microsoft.codecoverage\15.8.0\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:$output $_.FullName
}

要使其正常工作,请确保已为市场安装了“内联PowerShell”任务,并将其放在生成管道中的“运行代码分析”步骤之前。

对于使用自托管代理的用户,您还可以安装

它包含一个CodeCoverage.exe文件SonarQubeAnalyze@4Azure DevOps任务将找到。根据本文,SonarQube将能够将.coverage文件转换为.coverage XML


VisualStudio测试代理似乎是免费的。无需支付Visual Studio Enterprise的费用

@jessehouwing它的版本是6.7(build 33306),社区版。将其添加到初始问题中。将/d:sonar.verbose=true/d:sonar.cs.vscoveragexml.reportspath=***.coveragexml添加到准备SonarQube分析任务的其他设置中,并将System.debug变量设置为true,然后在OneDrive上排队构建并共享日志。sonarqube end analysis任务期间,.coverage文件将转换为coverage xml,因此您可以共享sonarqube end analysis任务的详细日志。我已将日志添加到帖子中,似乎xml文件生成正确。无论如何,它并没有传递给SonarQube。我已经阅读了关于这个问题和解决方法的文章。问题是,没有可用的.coveragexml文件。只有一个二进制的.coverage文件。因此,要使此解决方案真正起作用,我需要将二进制文件转换为xml格式。您能否检查代理(正在运行您的构建)是否具有CodeCoverage工具?请查看我自己的日志:我从VSTS分析结束部分(不是全部)添加了日志。coveragexml文件似乎生成正确,但它毕竟似乎还没有到达SonarQube。我一开始一定是添加了reportsPaths属性不正确。我重新跟踪我的步骤,现在它工作了。谢谢你的帮助!