gpt4 book ai didi

azure-devops - 发布管道 Azure Devops 代码覆盖率报告

转载 作者:行者123 更新时间:2023-12-04 12:11:31 28 4
gpt4 key购买 nike

我正在尝试在我的 Azure DevOps Pipeline 中在线发布一份详细报告,但我得到的只是一个下载此 Coverage 文件的链接。 (自 Visual Studio 2019 以来,社区版本无法再读取该内容)
enter image description here
这是我的管道:

trigger:
branches:
include:
- '*'

pool:
vmImage: 'windows-2019'

steps:
- task: NuGetToolInstaller@0
displayName: Instal Nuget
inputs:
checkLatest: true

- task: NuGetCommand@2
displayName: Restore Nuget Packages
inputs:
restoreSolution: '**/*.sln'

- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
version: 3.1.x
performMultiLevelLookup: true

- task: DotNetCoreCLI@2
displayName: Build Tests
inputs:
command: 'build'
projects: '**/OneTienditaUnitTests/*.csproj'
arguments: '--configuration Release'

- script: dotnet test OneTienditaUnitTests --logger trx --collect "Code coverage"

- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'

- task: XamarinAndroid@1
displayName: Build Android App
inputs:
projectFile: '**/*Android*.csproj'
outputDirectory: '$(build.binariesDirectory)/Release'
configuration: 'Release'
如果我像这样使用 Cobertura,则不起作用:
- task: DotNetCoreCLI@2
displayName: Run Tests
inputs:
command: 'test'
projects: '**/OneTienditaUnitTests/*.csproj'
arguments: '--configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=../reports/coverage/'

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(build.sourcesdirectory)\reports\coverage\coverage.cobertura.xml'
reportDirectory: '$(build.sourcesdirectory)\reports\coverage'
请任何帮助?我不是专业的 DevOps

最佳答案

要发布报告,您需要使用 Cobertura。对于 TRX,您只会获得下载文件的链接。要创建 Cobertura 报告,您需要在测试项目中安装 coverlet.collector nuget 包。在这里,您有代码可以解决您的问题:

# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true'
workingDirectory: $(Build.SourcesDirectory)

- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool

- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml
[2021 更新]
您不需要额外的任务来安装/运行自定义 ReportGenerator 工具:它现在是阅读的默认工具 coverage.cobertura.xml文件并包含在 dotnet 中命令行界面。
但是,默认情况下,它会将 cobertura xml 文件保存到代理上的临时目录中。所以,你只需要更新 summaryFileLocationPublishCodeCoverageResults任务指向临时目录并跳过“中间人”步骤:
# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage"'

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'

关于azure-devops - 发布管道 Azure Devops 代码覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64592534/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com