早上好,
抱歉打扰你,我有问题,我没有线索。
我在 Azure DevOps 上有一个管道,当我使用命令“dotnet test”时,我使用 Coverlet 生成代码覆盖率报告。
事实上,该报告生成良好。
首先,在“准备对 SonarQube 的分析”步骤中,我设置了变量“sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml”。
然而,在我的 SonarQube 中,代码覆盖率为 0%……我不知道该怎么做,也不知道有什么线索……
谢谢
最佳答案
我无法重现上述问题。而且很难排除故障,因为您没有共享 的配置dotnet 测试任务 或 sonarqube 准备任务 .
我创建了一个测试项目,覆盖范围已成功发布到我的 sonarqube 服务器。你可以引用下面我的步骤。
1、创建sonarqube服务器并配置我的projectName和projectKey(我使用azure sonarqube容器实例,详情查看here)。
2、配置sonarqube service connection在 azure devops 中。
3、创建构建管道。我使用 yaml 管道。
在 准备分析配置任务 ,我选择使用独立扫描仪 , 和 模式是 手动提供配置 .我设置了变量 sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml"
.
下面的屏幕截图是经典 ui View 中的任务设置。
在我的 dotnet 测试任务 我设置参数如下,具体输出覆盖结果到$(Agent.TempDirectory)/
文件夹。arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
Below is the full content of my azure-pipelines.yml file.
trigger: none
jobs:
- job: 'Tests'
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
continueOnError: true
steps:
- task: SonarQubePrepare@4
displayName: 'Prepare analysis on SonarQube'
inputs:
SonarQube: sonarlevi
scannerMode: CLI
configMode: manual
cliProjectKey: myproject2
cliProjectName: myproject2
extraProperties: |
sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml"
- task: DotNetCoreCLI@2
inputs:
command: restore
projects: '**\*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- task: DotNetCoreCLI@2
displayName: Test .NET
inputs:
command: test
projects: '**\*Test*.csproj'
publishTestResults: false
arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
condition: succeededOrFailed()
- task: SonarQubeAnalyze@4
displayName: 'Run Code Analysis'
- task: SonarQubePublish@4
displayName: 'Publish Quality Gate Result'
关于.net-core - Azure Devops + Coverlet + SonarQube 显示 0%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60111864/