4

I do use PublishCodeCoverageResults@2 task in my Azure DevOps pipeline

- task: PublishCodeCoverageResults@2
  inputs:
    codeCoverageTool: 'JaCoCo'
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/target/site/jacoco-aggregate/**/jacoco.xml'
    reportDirectory: '$(System.DefaultWorkingDirectory)/target/site/jacoco-aggregate/'
    pathToSources: '$(System.DefaultWorkingDirectory)/**/src/main/java/'
    failIfCoverageEmpty: false

Everything works nicely but the odd thing is - while running this task the Code Coverage shows me the Jacoco html reports, view looks like this

Code Coverage view while pipeline task is running

and here the Code Coverage View after the pipeline finished

Code Coverage View after pipeline task finished

The second view is not useful, cause you can't navigate into the class and see the code, while with the jacoco html reports this is possible.

Drilldown to Classes

What am I doing wrong? Or why is the view changing? How can I avoid this behaviour?

3 Answers 3

4

I can see two possible things that might be wrong.

  1. There are two versions of this task available with slightly different syntax. You're using inputs (codeCoverageTool, reportDirectory) that aren't available in version 2. These "illegal" properties are ignored at runtime and have no effect.

    The syntax between versions:

    • PublishCodeCoverageResults@1

      - task: PublishCodeCoverageResults@1
        inputs:
          codeCoverageTool: # string. Required. 'Cobertura' | 'JaCoCo'
          summaryFileLocation: # string. Required. Summary file
          pathToSources: # string. Path to source files.
          reportDirectory: # string. Report directory.
          additionalCodeCoverageFiles: # string. Additional files.
          failIfCoverageEmpty: # boolean
      
    • PublishCodeCoverageResults@2

      - task: PublishCodeCoverageResults@2
        inputs:
          summaryFileLocation: # string. Required. Path to summary files.
          pathToSources: # string. Path to Source files
          failIfCoverageEmpty: # boolean
      
  2. Both the v1 and v2 documentation states that the pathToSources must be an absolute path:

    Specifying a path to source files is required when coverage XML reports don't contain an absolute path to source files. For example, JaCoCo reports don't use absolute paths, so when publishing JaCoCo coverage for Java apps, the pattern is similar to $(System.DefaultWorkingDirectory)/MyApp/src/main/java/. This input should point to an absolute path to source files on the host. For example, $(System.DefaultWorkingDirectory)/MyApp/.

Remove the wildcards ** in your pathToSources to ensure the report is properly generated. The variable $(System.DefaultWorkingDirectory) represents an absolute path to the root of your repository.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks very much. I do get following error "No source directories supplied for 'JaCoCo' coverage file" and "File 'Adapter1.java' does not exist (any more).". But the reason why I do have wildcards ( '$(System.DefaultWorkingDirectory)/**/src/main/java/' ) is cause I do have a multi-module project and different src-folders, meaning under $(System.DefaultWorkingDirectory) there are module1/src/main/java and module2/src/main/java etc.. Now I try with a string of paths separated by semicolon:
--> pathToSources: '$(System.DefaultWorkingDirectory)/module1/src/main/java/;$(System.DefaultWorkingDirectory)/module2/src/main/java/ '
It worked with above pathToSources. Happy happy happy! Thanks very much!!
2

I came across the same problem and this behaviour is by design as I found out after googling for a while (also in the Reportgenerator GitHub repo, https://github.com/danielpalme/ReportGenerator/issues/646). There is no way to get the detailed html report with links to src based pages when using the V2 task.

With V1 this is working but now there is a deprecation warning when using V1.

Comments

-3
- task: PublishCodeCoverageResults@2
  inputs:
    codeCoverageTool: 'JaCoCo'
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/target/site/jacoco-aggregate/**/jacoco.xml'
    reportDirectory: '$(System.DefaultWorkingDirectory)/target/site/jacoco-aggregate/'
    pathToSources: '$(System.DefaultWorkingDirectory)/**/src/main/java/'
    failIfCoverageEmpty: false

2 Comments

Thank you, but unfortunately this didn't help.
This is PublishCodeCoverageResults task version 1, and not 2. @MD, please fix it or remove it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.