Search code examples
.netazureunit-testingazure-devopsazure-pipelines

Azure, .Net, Cobertura - ##[warning]Multiple file or directory matches were found


Hi i am trying to get code coverage with .net5 in azure pipeline.

Run tests (not entire file)

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

Publish tests(not entire file)

##[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

And of course my pipeline

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"

Why is more then one XML generated? I am basically balancing between no XML and more XML. I am just unable to generate one XML. (on my localhost it generates only one) Thanks for any tips.


Solution

  • UPDATE 06.05.2024

    You can use version 2 which allows you to pass multiple files without merging them first:

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

    summaryFileLocation - Path to summary files

    Specifies the path of the summary file containing code coverage statistics, such as line, method, and class coverage. Multiple summary files are merged into a single report. The value may contain minimatch patterns. For example: $(System.DefaultWorkingDirectory)/MyApp/**/site/cobertura/coverage.xml

    OLD ANSWER

    Please replace your PublishCodeCoverageResults with the following steps:

           - 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'
    

    And you have multiple files, because probably you have more than one test project.