【问题标题】:Azure Devops CI/CD CodeCoverage with ymlAzure Devops CI/CD CodeCoverage with yml
【发布时间】:2021-02-11 14:58:48
【问题描述】:

我尝试为我的 webapi 创建代码覆盖率。我关注了this link

我已更改 YML 文件并在 Azure Devops 中收到以下构建失败错误。

我为此使用了以下代码。如何解决这个问题?

steps:
- task: DotNetCoreCLI@2
  displayName: 'Build project'
  inputs:
    projects: '**/*.csproj'
    arguments: '--output $(Build.BinariesDirectory) --configuration Release'

- task: DotNetCoreCLI@2
  displayName: 'Install .NET Core tools from local manifest'
  inputs:
    command: custom
    custom: tool
    arguments: 'restore'

- task: VSTest@2
  displayName: 'Unit Tests'
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*Tests*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(Build.BinariesDirectory)'

    arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.BinariesDirectory)/TestResults/Coverage/'
    publishTestResults: true
    projects: '**/*.Tests.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Create code coverage report'
  inputs:
    command: custom
    custom: tool
    arguments: 'run reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage report'
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'

【问题讨论】:

  • 输出的第 17 和 18 行告诉您问题所在。您指定的路径无效并且找不到任何报告。我无法从您的 YAML 中得知 reportgenerator 是什么工具,所以我很难详细说明修复。
  • 嗨@mohan,刚刚签到看看这个问题现在是否仍然阻碍你?这个问题有什么更新吗?

标签: asp.net-web-api azure-devops azure-pipelines code-coverage azure-pipelines-yaml


【解决方案1】:

您的单元测试任务将输出放在$(Build.BinariesDirectory) 下,但您的报告任务指定$(Build.SourcesDirectory)。现在,如果二进制文件在源代码中,这可能是正确的,但如果没有这些值,我无法确定。

我会排除我会验证文件是否存在于您期望的位置。尝试在覆盖任务之前将其添加到您的管道中:

  - pwsh: |
      Write-Host "Checking Sources"
      Get-ChildItem $(Build.SourcesDirectory)/coverage.cobertura.xml -Recurse
      Write-Host "Checking Binaries"
      Get-ChildItem $(Build.BinariesDirectory)/coverage.cobertura.xml -Recurse

再次运行管道并查看该任务的日志输出。如果该文件存在,则可能与工具安装有关。

【讨论】:

  • 感谢您的帮助!它没有按预期工作
  • 什么不起作用?你能包括一些日志输出吗?
  • 我收到以下错误。添加上述行后,构建失败。 /azure-pipelines.yml: (Line: 47, Col: 5, Idx: 1185) - (Line: 47, Col: 6, Idx: 1186): 解析块映射时,没有找到预期的键。
  • 尝试将“pwsh”更改为“powershell” - 我认为您在托管代理上,并且可以使用。如果这不起作用,请发布 YAML 的整个部分以获取上下文!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 2020-12-20
  • 2020-04-07
  • 2021-11-05
  • 2023-03-28
相关资源
最近更新 更多