azure-pipelines-tasks: PublishCodeCoverageResults@2 fails to write report to reportDirectory

Required Information

Type: Bug Task Name: PublishCodeCoverageResults@2

Environment

  • Server: Azure Pipelines
  • Agent: MS hosted Ubuntu-22.04

Issue Description

PublishCodeCoverageResults@2 produces an invalid command to the underlying program

Ran with the following template

steps:
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '2.1.x'
  - task: PublishCodeCoverageResults@2
    inputs:
      codeCoverageTool: Cobertura
      summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'

Error logs

Starting: PublishCodeCoverageResults
==============================================================================
Task         : Publish code coverage results
Description  : Publish any of the code coverage results from a build
Version      : 2.215.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/publish-code-coverage-results
==============================================================================
CoveragePublisher.Console 1.0.0
Copyright (C) 2023 CoveragePublisher.Console

ERROR(S):
  Option 'reportDirectory 
/home/vsts/work/_temp/c2a6c08c-dd26-417e-925a-9a9502100a9e' is unknown.

  --reportDirectory    (Default: ) Path where html report will be generated.

  --sourceDirectory    (Default: ) List of source directories separated by ';'.

  --timeout            (Default: 120) Timeout for CoveragePublisher in seconds.

  --noTelemetry        (Default: false) Disable telemetry data collection.

  --help               Display this help screen.

  --version            Display version information.

  value pos. 0         Required. Set of coverage files to be published.


Found 2 result(s) matching pattern: /home/vsts/work/_temp/**/coverage.cobertura.xml
/home/vsts/work/_temp/595a46d5-239e-47eb-8b18-452278343573/coverage.cobertura.xml
/home/vsts/work/_temp/_fv-az363-480_2023-02-13_14_17_13/In/fv-az363-480/coverage.cobertura.xml
/opt/hostedtoolcache/dotnet/dotnet /home/vsts/work/_tasks/PublishCodeCoverageResults_2a7ebc54-c13e-490e-81a5-d7561ab7cd97/2.215.0/node_modules/coveragepublisher/CoveragePublisher/CoveragePublisher.Console.dll "/home/vsts/work/_temp/595a46d5-239e-47eb-8b18-452278343573/coverage.cobertura.xml" "/home/vsts/work/_temp/_fv-az363-480_2023-02-13_14_17_13/In/fv-az363-480/coverage.cobertura.xml" --reportDirectory /home/vsts/work/_temp/c2a6c08c-dd26-417e-925a-9a9502100a9e
Finishing: PublishCodeCoverageResults

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 29
  • Comments: 28

Commits related to this issue

Most upvoted comments

Ran into the exact same issue. Seems like it’s time for a @3. Why do we need to use a dotnet version that’s end of life anyway?

Hi, everyone! I did an workaround for this issue. Im just bypassing the native task and running it as a CmdLine. Notice the tasks UseDotnet@2 and PublishCodeCoverageResult@2 are nedded to download dependencies.

steps:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '2.1.x'
    
- task: Npm@1
  inputs:
    command: 'install'
    customCommand: 'Npm install'

- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run coverage' #HERE YOU USE YOUR COVERAGE SCRIPT
  displayName: 'Tests Running'
  continueOnError: true


- task: PublishCodeCoverageResults@2
  condition: eq('true', 'false') # THIS WILL NEVER RUN ONCE TASK DECLARATION IS NEEDED TO DOWNLOAD IT SOURCES
  inputs:
    summaryFileLocation: PATH/TO/YOUR/COVERAGE.xml
    
# here the magic happens
# CREATE A DIR TO USE IN reportDirectory parameter
# Run publish as bash command
- task: CmdLine@2
  displayName: Publish Code Coverage
  env: { 'SYSTEM_ACCESSTOKEN': $(System.AccessToken) } #access token is needed to upload report to azure pipeline tabs
  inputs:
    script: |
      mkdir /home/vsts/work/_temp/cobertura 
      /opt/hostedtoolcache/dotnet/dotnet `find /home/vsts/work/_tasks/ -name CoveragePublisher.Console.dll` "PATH/TO/YOUR/COVERAGE.xml" --reportDirectory /home/vsts/work/_temp/cobertura

In short based on what I see here and in my own use of PublishCodeCoverageResults:

  • @2 is broken and–I’ll bet–underfunded.
  • @1 works just fine and doesn’t require any special care.
  • An alternative that’s just as easy and more flexible: run the tool from the command line.

I’ll go with the middle option for now: @1.

So is this task actually working now or should I not waste time trying to get it to work 🗡️? Seems that something got updated somewhere and the solution that was presented earlier no longer works.

Seems that something is broken again…

      - task: UseDotNet@2
        displayName: 'Use .NET Core sdk'
        inputs:
          packageType: sdk
          version: 2.1.x
          installationPath: $(Agent.ToolsDirectory)/dotnet
      
      - task: PublishCodeCoverageResults@2
        condition: eq('true', 'false') # THIS WILL NEVER RUN, TASK DECLARATION IS NEEDED TO DOWNLOAD SOURCES
        inputs:
          summaryFileLocation: '$(Build.SourcesDirectory)/output/coverage.xml'

# Run publish as bash command - task is broken - https://github.com/microsoft/azure-pipelines-tasks/issues/13257
      - task: CmdLine@2
        displayName: Publish Code Coverage
        env: { 'SYSTEM_ACCESSTOKEN': $(System.AccessToken) }
        inputs:
          script: |
            mkdir /home/vsts/work/_temp/JaCoCo 
            /opt/hostedtoolcache/dotnet/dotnet `find /home/vsts/work/_tasks/ -name CoveragePublisher.Console.dll` '$(Build.SourcesDirectory)/output/coverage.xml' --reportDirectory /home/vsts/work/_temp/JaCoCo
      

It’s worked flawlessly for the past few months but I get a framework mismatch now ( as if it does not respect that I stated to use 2.1.x earlier…’

It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
  - Check application dependencies and target a framework version installed at:
      /opt/hostedtoolcache/dotnet/
  - Installing .NET Core prerequisites might help resolve this problem:
      https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
  - The .NET Core framework and SDK can be installed from:
      https://aka.ms/dotnet-download
  - The following versions are installed:
      2.1.30 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

Tried to use UseDotNet@2 ver 2.x but no dice

The specified framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
  - Check application dependencies and target a framework version installed at:
      /opt/hostedtoolcache/dotnet/
  - Installing .NET Core prerequisites might help resolve this problem:
      https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
  - The .NET Core framework and SDK can be installed from:
      https://aka.ms/dotnet-download
  - The following versions are installed:
      2.2.7 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

And of course if you try to use 3.1.x you get:

Starting: Publish Code Coverage
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/8d9f79c5-0d99-47ce-9fd3-d079a8dc37d8.sh
2023-05-25T07:09:14: Loading report '/home/vsts/work/1/s/output/coverage.xml' 1/1 in memory
2023-05-25T07:09:14: Preprocessing report
2023-05-25T07:09:14:   No source directories supplied for 'JaCoCo' coverage file
2023-05-25T07:09:14: Initiating parser for JaCoCo
2023-05-25T07:09:14: Current Assembly: Source/Private
2023-05-25T07:09:15: Current Assembly: Source/Public
2023-05-25T07:09:15: Finished parsing '/home/vsts/work/1/s/output/coverage.xml' 1/1
2023-05-25T07:09:15: Parsing of 1 files completed
2023-05-25T07:09:15: Starting merging result 1
2023-05-25T07:09:15: Finished merging result 1
##[error]Error occured while generating HTML report. Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken='. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
Publishing file coverage data.
Publishing code coverage HTML report.
Uploading 0 files.
File upload succeed.
Published '/home/vsts/work/_temp/JaCoCo' as artifact 'Code Coverage Report_146935'.
Finishing: Publish Code Coverage

I don’t think I’ll be only one to say that this is getting irritating…

Ran into the exact same issue. Seems like it’s time for a @3. Why do we need to use a dotnet version that’s end of life anyway?

My though exactly - this whole thing is just a big facepalm. And why can’t the mess be encapsulated instead of irritating all ADO users, after all it’s not exactly rocket-science going on here…