Eugene
Eugene

Reputation: 211

Azure PublishCodeCoverageResults@2 issue with detailed report for coverage

I'm trying to switch PublishCodeCoverageResults from @1 to @2. Because appeared warnig in pipeline

##[warning]New V2 version of task publishing code coverage results is available to all our customers now. We highly recommend to stop using the V1 version and migrate to V2 version (https://learn.microsoft.com/azure/devops/pipelines/tasks/reference/publish-code-coverage-results-v2). For more details, see - https://devblogs.microsoft.com/devops/new-pccr-task.

Currently, I'm using this code to obtain the report

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(Agent.BuildDirectory)/app_folder/coverage.xml'
  displayName: 'Publish Coverage Report'

After finishing, I receive a detailed report that allows me to go through the code and investigate the coverage.

PublishCodeCoverageResults@1 report

But when I'm trying to switch to PublishCodeCoverageResults@2

- task: PublishCodeCoverageResults@2
  inputs:
    summaryFileLocation: '$(Agent.BuildDirectory)/app_folder/coverage.xml'
    pathToSources: '$(Agent.BuildDirectory)/app_folder/'
  displayName: 'Publish Coverage Report'

and can got only common not useful report

PublishCodeCoverageResults@2 report

I've been trying different approaches according the official documentation, but eventually I didn't get detailed report and any artifacts after run.

Maybe somebody is facing with this issue. Thanks for the advice in advance.

Run tools: pytest and coverage.py

Upvotes: 21

Views: 4616

Answers (2)

Manoj N D
Manoj N D

Reputation: 67

for me this code worked even I was facing issues with the upgrading code coverage results to version 2

    displayName: 'Install .NET Core SDK'
    inputs:
      packageType: 'sdk'
      version: '8.x'
      performMultiLevelLookup: true
      includePreviewVersions: true
  - script: |
      dotnet --version
    displayName: 'Check .NET SDK Version'
  - task: PublishCodeCoverageResults@2
    displayName: 'Publish Code Coverage'
    inputs:
      codeCoverageTool: Cobertura
      summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
      failIfCoverageEmpty: true

I used this document template : https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/customize-python?view=azure-devops "Publish code coverage results"

Upvotes: 0

rgrace-puck
rgrace-puck

Reputation: 943

The new version of this task (V2) DOES NOT currently support branch or line based coverage details. Documentation is severely lacking and doesn't mention this huge gap in functionality; you have to read comments on the MS blog post to find this information.


Comments from Bohdan Janousek (MSFT)

https://devblogs.microsoft.com/devops/new-pccr-task/#comment-4300

Yes, the current gap between V1 and V2 (missing line and branch based coverage) is because the V2 does not use the report generator internally. There were issues with report generator for larger repositories and that is one of the reasons to move away from that.

https://devblogs.microsoft.com/devops/new-pccr-task/#comment-4298

We do expect to close the gap between the V2 and V1. Mainly the line based coverage. The V2 task is not using the report generator and there are no plans to rely on that. Nonetheless there still may be benefit on the V2 task – code coverage for folders and there can be set build quality checks to ensure respective folders will meet the requirements that may differ from the overall coverage required.

Also see: https://github.com/microsoft/azure-pipelines-tasks/issues/19295

Upvotes: 17

Related Questions