VSTS的SonarQube代码覆盖率 [英] SonarQube Code Coverage from VSTS
问题描述
我正在使用VSTS托管代理VS2017来运行构建,测试和SonarQube分析.我正在使用来自市场的SonarQube扩展( https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube ).使用的任务版本是4,它将SonarQube Scanner用于MSBuild 4.0.2.
I'm using VSTS hosted agent VS2017 to run the build, tests, and SonarQube analysis. I'm using the SonarQube extension from the marketplace (https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube). Task version in use is 4 which uses SonarQube Scanner for MSBuild 4.0.2.
分析效果很好,但是它不能将代码覆盖率结果转换为SonarQube.我可以在VSTS(构建详细信息)中看到代码覆盖率分析,而在SonarQube中看不到.
The analysis works well, but it doesn't translate the code coverage results to the SonarQube. I can see the Code Coverage analysis in VSTS (build details), but not in SonarQube.
据我了解,问题在于VSTS生成扩展名为.codecoverage的二进制文件. SonarQube不知道如何处理该文件.我无法将其转换为XML格式,因为我似乎无能为力.
In my understanding, the problem is that VSTS generates a binary file with an extension .codecoverage. SonarQube doesn't know how to handle this file. I'm having trouble converting this to XML format as it seems I have no means to do it.
有人在SonarQube上成功使用了VSTS,并且也将代码覆盖率结果也带到了SonarQube吗?您如何设置?
Has someone used VSTS successfully with SonarQube and got the Code Coverage results to SonarQube as well? How have you set it up?
编辑1
我使用的SonarQube版本是:6.7版(内部版本33306),社区版
EDIT 1
SonarQube version that I'm using is: Version 6.7 (build 33306), Community Edition
编辑2
分析的最后实际上生成了xml文件,如下面的注释中所述.这是从日志中获得的:
EDIT 2
The end of analysis actually generates the xml-file, like was stated in the comments below. This is from the logs:
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扩展名应该自动导入coverage结果,但是目前存在(希望如此)将很快得到修复的回归:
The VSTS extension should automatically import the coverage results, but there is currently a regression that will be fixed (hopefully) soon: SONARMSBRU-339
同时, VSTS扩展文档中介绍了一种解决方法在分析.NET解决方案" 中:在Additional Properties
文本区域中,添加以下属性:
Meanwhile, there is a workaround explained in the VSTS extension documentation in "Analysing a .NET solution": in the Additional Properties
text area, add the following property:
sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
这篇关于VSTS的SonarQube代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!