This below code is the one which we use to publish the code coverage results now.
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov'
additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/**'
We are using the above code to publish the code coverage version 1 since in the DevOps we are getting too much warnings.
##[warning]The PublishCodeCoverageResults@1 is deprecated. Users are recommended to switch to task version 2. For more details, see https://devblogs.microsoft.com/devops/new-pccr-task
and
##[warning]Task 'Publish code coverage' version 1 (PublishCodeCoverageResults@1) is deprecated.
My teammates asked me to upgrade to version 2, I went through the official documentations and version 2 is s**t it's actually downgrade version from version 1 https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/customize-javascript?view=azure-devops and https://devblogs.microsoft.com/devops/new-pccr-task/#comment-4298
They are of no help.
I used this code to publish the code coverage since for version 2 it asked me to install and use Dotnet
- task: UseDotNet@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'
reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov'
additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/htmlcov/**'
but my code coverage is not properly publishing the reports are not generating properly at all.
so someone please help me, to generate and publish the code coverage using version 2.
I solved the problem by my own. 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"