I have a Spring boot application. I am using the Azure CICD pipeline for delivery. I am using the sonar cloud for code quality analysis and configured it in the pipeline as a step. When the pipeline runs the sonar cloud dashboard gets updated with the vulnerabilities, code smells, etc... But the code coverage is always shown as 0%. There are a lot of tests in my application and not sure why it is not reflecting in the sonar cloud. My pipeline looks like this (major steps):
steps:
- install java step here
- configure maven step here
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'My Sonarcloud connection'
organization: 'myOrganization'
scannerMode: 'Other'
extraProperties: |
sonar.projectKey=myOrganization_JavaApp---API
sonar.projectName=JavaApp - API
- task: Maven@3
displayName: 'Build Maven Artifacts'
inputs:
mavenPomFile: 'pom.xml'
goals: 'package -Dactive.profile=$(active_profile)'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
codeCoverageToolOption: 'JaCoCo'
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
- task: CopyFiles@2
displayName: 'Copy Artifacts to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**/target/**/*.war'
TargetFolder: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact to: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
Once the pipeline runs, it shows all the code coverage details in CICD job.
However, the coverage is not reflected in the sonar cloud. It is always 0%
I would like to know two things
pom.xml
to make this work?Testing from my side, adding sonar.coverage.jacoco.xmlReportPaths=<path-to-xml-report>
in SonarCloudPrepare@1 task can resolve the issue.
My SonarCloudPrepare@1 task:
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis configuration'
inputs:
SonarCloud: 'SonarCloudSC'
organization: '***sonarcloudorg'
scannerMode: 'Other'
extraProperties: |
sonar.projectKey=***
sonar.projectName=***
sonar.coverage.jacoco.xmlReportPaths= CCReport43F6D5EF/jacoco.xml