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
and here the Code Coverage View after the pipeline 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.
What am I doing wrong? Or why is the view changing? How can I avoid this behaviour?
I can see two possible things that might be wrong.
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:
- 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
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: # string. Required. Path to summary files.
pathToSources: # string. Path to Source files
failIfCoverageEmpty: # boolean
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.