【发布时间】:2019-08-28 22:47:17
【问题描述】:
我正在使用 VSTS 托管代理 VS2017 来运行构建、测试和 SonarQube 分析。我正在使用市场上的 SonarQube 扩展 (https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube)。正在使用的任务版本是 4,它使用 SonarQube Scanner for MSBuild 4.0.2。
分析运行良好,但它没有将代码覆盖率结果转换为 SonarQube。我可以在 VSTS(构建详细信息)中看到代码覆盖率分析,但在 SonarQube 中看不到。
据我了解,问题在于 VSTS 生成了一个扩展名为 .codecoverage 的二进制文件。 SonarQube 不知道如何处理这个文件。我无法将其转换为 XML 格式,因为我似乎没有办法做到这一点。
是否有人成功地将 VSTS 与 SonarQube 一起使用,并将代码覆盖率结果也发送到了 SonarQube?你是怎么设置的?
编辑 1
我正在使用的 SonarQube 版本是:6.7 版(内部版本 33306),社区版
编辑 2
分析结束实际上会生成 xml 文件,如下面的 cmets 所述。这是来自日志:
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...
【问题讨论】:
-
@jessehouwing 它是 6.7 版(内部版本 33306),社区版。将其添加到最初的问题中。
-
将 /d:sonar.verbose=true /d:sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml 添加到准备 SonarQube 分析任务的附加设置中,并将 System.debug 变量设置为true,然后在 OneDrive 上排队构建和共享日志。
-
在sonarqube端分析任务中.coverage文件会被转换成coveragexml,所以你可以分享sonarqube端分析任务的详细日志。
-
我已将日志添加到帖子中,并且似乎正在正确生成 xml 文件。无论如何,它不会传递给 SonarQube。
标签: sonarqube azure-devops code-coverage