【问题标题】:OpenCover is not uploaded in Azure DevopsOpenCover 未在 Azure Devops 中上传
【发布时间】:2023-03-11 06:10:01
【问题描述】:

我正在尝试在 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'

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

这是日志:

D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.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%...

【问题讨论】:

  • 您使用的是自托管还是托管代理? ../coverage.opencover.xml 是否包含您期望的覆盖率数据?你能在你的构建日志中看到这个文件吗?
  • 我正在使用自主机,文件coverage.opencover.xml 已正确生成,我已在reportgenerator 任务中使用它。我也可以在日志中看到它。只是声纳没有接收到它......

标签: .net-core azure-devops msbuild sonarqube sonarcloud


【解决方案1】:

好吧,我的错,报道实际上是正确报道的。

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

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

谢谢大家。

【讨论】:

    猜你喜欢
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 2020-05-25
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多