Search code examples
azureazure-devopsazure-pipelinesjacocojacoco-maven-plugin

Azure DevOps "Code Coverage" view changes after pipeline run finished


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?


Solution

  • 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.