【问题标题】:Azure Devops + Coverlet + SonarQube shows 0%Azure Devops + Coverlet + SonarQube 显示 0%
【发布时间】:2020-05-23 11:55:14
【问题描述】:

早上好,

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

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

确实,报告生成得很好。

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

然而在我的 SonarQube 中,代码覆盖率是 0%...我不知道该做什么或任何线索...

谢谢

【问题讨论】:

  • 嗨@Alex Planchon 你检查了下面的步骤吗?如果有任何问题,请告诉我。
  • @LeviLu-MSFT 我刚刚发布了我的“解决方案”,它现在正在工作:)

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


【解决方案1】:

我无法重现上述问题。由于您没有共享 dotnet 测试任务sonarqube 准备任务 的配置,因此很难进行故障排除。

我创建了一个测试项目,并且覆盖范围已成功发布到我的 sonarqube 服务器。你可以参考下面我的步骤。

1、创建sonarqube服务器并配置我的projectName和projectKey(我使用azure sonarqube容器实例,详情请查看here)。

2、在azure devops中配置sonarqube service connection

3、创建构建管道。我使用 yaml 管道。

Prepare Analysis Configuration任务中,我选择UsestandalonescannerModeManually provide configure .我设置了变量sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml"

下面的截图是经典ui视图中的任务设置。

在我的dotnet测试任务中,我将参数设置如下,并将覆盖结果具体输出到$(Agent.TempDirectory)/文件夹。

arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'

以下是我的 azure-pipelines.yml 文件的完整内容。

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'   

【讨论】:

    【解决方案2】:

    我做了很多事情来最终设法让覆盖工作,但我认为问题是我的解决方案的每个 .csproj 中缺少“ProjectGUID”,导致 SonarQube 扫描仪忽略了项目。

    我也同时从 SonarQube 6.2 升级到 8.1,这可能已经解决了这个问题。

    为了完成这项工作,我的步骤保持不变。

    【讨论】:

      猜你喜欢
      • 2022-11-12
      • 2019-07-17
      • 1970-01-01
      • 2020-08-19
      • 2020-02-12
      • 1970-01-01
      • 2020-08-21
      • 2019-05-14
      • 1970-01-01
      相关资源
      最近更新 更多