OpenCover 未上传到 Azure Devops

OpenCover is not uploaded in Azure Devops

我正在尝试在 sonarcloud 中连接我的项目。我使用 Azure Devops Yaml 管道构建和启动我的测试。这是正在发生的事情的摘要。

首先我有一个准备分析任务:

  - task: SonarCloudPrepare@1
    displayName: 'Prepare analysis on Sonarcloud'
    inputs:
      SonarCloud: 'Sonarcloud'
      organization: ***redacted***
      scannerMode: 'MSBuild'
      projectKey: ***redacted***
      projectName: ***redacted***
      extraProperties: |
        sonar.exclusions=**/obj/**,**/*.dll
        sonar.branch.name=$(Build.SourceBranchName)
        sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
        sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx

然后我构建项目,这里一切正常。 然后我启动测试,并使用报告生成器为我的 Azure 管道创建一个 html 报告:

  - task: DotNetCoreCLI@2
    displayName: dotnet test
    inputs:
      command: test
      arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
      projects: 'Tests/**/*.csproj'
      nobuild: true

  - script: |
      dotnet tool install -g dotnet-reportgenerator-globaltool
      reportgenerator "-reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml" "-targetdir:$(Build.SourcesDirectory)/CodeCoverage" "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
    displayName: Create Code coverage report

  - task: PublishCodeCoverageResults@1
    displayName: 'Publish code coverage'
    inputs:
      codeCoverageTool: Cobertura
      summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
      reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'

再次一切正常,测试 运行,计算覆盖率,生成报告。

然后我安装 typescript(用于声纳分析)并 运行 代码分析:

  - script: |
      cd $(Build.SourcesDirectory)/Src/***ProjectDir***
      npm install typescript
    displayName: 'Install typescript for sonar analysis'
  - task: SonarCloudAnalyze@1
    displayName: 'Run code analysis'
    continueOnError: false
  - task: SonarCloudPublish@1
    displayName: 'Publish code analysis'
    continueOnError: false
    inputs:
      pollingTimeoutSec: '300'

声纳分析找到了 trx 文件,但没有找到 opencover 覆盖率报告,即使在准备分析任务的 sonar.cs.opencover.reportsPaths 参数中提供了路径。

这是日志:

D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255.10.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.8
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
17:31:43.118  Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
17:31:43.197  Did not find any binary coverage files in the expected location.
17:31:43.197  Falling back on locating coverage files in the agent temp directory.
17:31:43.197  Searching for coverage files in D:\a\_temp
17:31:43.243  No coverage files found in the agent temp directory.

分析已正确上传到 sonarcloud,但覆盖率显示为 0%...

不好意思,报道实际上是正确的。

罪魁祸首是 sonar.branch.name=$(Build.SourceBranchName) 我第一次 运行 构建时没有这个选项,覆盖率不起作用,报告是完整的 b运行ch 名称:folder/branch。 然后我将它与其他覆盖参数一起添加,并且此参数剥离了 b运行ch 的文件夹,因此包含覆盖的新报告位于 b运行ch(没有文件夹)

然后我在刷新当然没有更新的报告

谢谢大家。