.net-core - Azure Devops + Coverlet + SonarQube 显示 0%

标签 .net-core azure-devops sonarqube code-coverage azure-pipelines

早上好,

抱歉打扰你,我有问题,我没有线索。

我在 Azure DevOps 上有一个管道,当我使用命令“dotnet test”时,我使用 Coverlet 生成代码覆盖率报告。

enter image description here

事实上,该报告生成良好。

enter image description here

首先,在“准备对 SonarQube 的分析”步骤中,我设置了变量“sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml”。

enter image description here

然而,在我的 SonarQube 中,代码覆盖率为 0%……我不知道该怎么做,也不知道有什么线索……

enter image description here

谢谢

最佳答案

我无法重现上述问题。而且很难排除故障,因为您没有共享 的配置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 中的任务设置。

enter image description here

在我的 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/

相关文章:

python - 当 PIP 不起作用时在 MS Azure 上安装包

c# - SonarQube 未更新报告 - "Line 5 is out of range for file Program.cs. File has 4 lines"

java - 规范合规性

Wpf 应用程序崩溃 - 错误模块名称 coreclr.dll 版本 : 4. 700.20.47201

rest - 网络选项卡中可见的用户名和密码

azure - 在运行 Powershell 脚本的 Azure DevOps 管道中传递脚本参数

visual-studio - 在 Visual Studio 中显示方法的认知复杂性

c# - EF Core 过滤器枚举存储为带有 LIKE 运算符的字符串

testing - 集成和单元测试不再适用于无法在运行时找到程序集的 ASP.NET Core 2.1

git - 如何在 azure devops 中设置默认分支策略