Azure、.Net、Cobertura - ##[警告]找到多个文件或目录匹配项

Mic*_*elo 10 .net unit-testing azure azure-devops azure-pipelines

您好,我正在尝试在 azure 管道中使用 .net5 获取代码覆盖率。

运行测试(不是整个文件)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Results File: /home/vsts/work/_temp/_fv-az43-964_2021-08-25_08_31_59.trx

Attachments:
  /home/vsts/work/_temp/f5dd5e9f-e260-437d-80ef-4fb917215b09/coverage.cobertura.xml
Passed!  - Failed:     0, Passed:    16, Skipped:     0, Total:    16, Duration: 732 ms - /home/vsts/work/1/s/sda2021_webapi/Test/sda2021_api.tests/bin/Release/net5.0/sda2021_webapi.tests.dll (net5.0)
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Async Command Start: Publish test results
Publishing test results to test run '5152'.
TestResults To Publish 16, Test run id:5152
Test results publishing 16, remaining: 0. Test run id: 5152
Published Test Run : https://dev.azure.com/sda-shs/Bratislava2021/_TestManagement/Runs?runId=5152&_a=runCharts
Async Command End: Publish test results
Finishing: Dotnet run tests
Run Code Online (Sandbox Code Playgroud)

发布测试(不是整个文件)

##[warning]Multiple file or directory matches were found. Using the first match: /home/vsts/work/_temp/_fv-az43-964_2021-08-25_08_31_59/In/fv-az43-964/coverage.cobertura.xml
/opt/hostedtoolcache/dotnet/dotnet /home/vsts/work/_tasks/PublishCodeCoverageResults_2a7ebc54-c13e-490e-81a5-d7561ab7cd97/1.189.0/netcoreapp2.0/ReportGenerator.dll -reports:/home/vsts/work/_temp/**/coverage.cobertura.xml -targetdir:/home/vsts/work/_temp/cchtml -reporttypes:HtmlInline_AzurePipelines
2021-08-25T08:32:03: Arguments
2021-08-25T08:32:03:  -reports:/home/vsts/work/_temp/**/coverage.cobertura.xml
Run Code Online (Sandbox Code Playgroud)

当然还有我的管道

task: DotNetCoreCLI@2
            displayName: Dotnet run tests
            inputs:
              command: "test"
              projects: "**/xxxxx/*.tests.csproj"
              arguments: '--configuration Release /p:CoverletOutputFormat=cobertura --collect:"XPlat Code Coverage" --no-build'
              testRunTitle: "xxxx"
          - task: PublishCodeCoverageResults@1
            displayName: "publish coverage results"
            inputs:
              codeCoverageTool: "Cobertura"
              summaryFileLocation: "$(Agent.TempDirectory)/**/coverage.cobertura.xml"
Run Code Online (Sandbox Code Playgroud)

为什么会生成多个 XML?我基本上在没有 XML 和更多 XML 之间进行平衡。我只是无法生成一个 XML。(在我的本地主机上它只生成一个)感谢您的任何提示。

Krz*_*tof 15

PublishCodeCoverageResults用以下步骤替换您的:

       - task: reportgenerator@4
         displayName: 'Merge code coverage reports'
         inputs:
           reports: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
           targetdir: '$(Pipeline.Workspace)/coverlet'
           reporttypes: 'Cobertura'
           verbosity: 'Verbose'
     
       - task: PublishCodeCoverageResults@1
         displayName: 'Publish code coverage results'
         inputs:
           codeCoverageTool: Cobertura
           summaryFileLocation: '$(Pipeline.Workspace)/coverlet/Cobertura.xml'
Run Code Online (Sandbox Code Playgroud)

并且您有多个文件,因为您可能有多个测试项目。