We have been attempting to get PHP Code coverage of a Magento project to report into SonarCloud. We’ve made any attempts to alter the configuration properties to get that data to appear in SonarCloud, but changing the paths didn’t make a difference. We also tried to change the version of the SonarCloud pipe in bitbucket from 1.2.1 to 1.3.0 hoping that would make them appear, but that didn’t work either.
I have ensured that the test reports are saved and passed through into the Sonar step but adding a step to display the contents of that file. I am able to see data from the coverage report being processed by the SonarScanner, so I don’t believe this is related to the test artifacts not being copied properly either. After making around 30 attempts to get coverage in by tweaking various parameters and build steps, I finally decided to run it locally so I could do further debugging without doing commits to our branch.
I ran the following command locally, and was able to get coverage to appear inside of SonarCloud.
sonar-scanner \
-Dsonar.organization=KEY \
-Dsonar.projectKey=KEY \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.sources=app/code \
-Dsonar.tests=app/code \
-Dsonar.exclusions=Magento2/ \
-Dsonar.coverage.exclusions=app/code/**/Test/Unit/**/*.php \
-Dsonar.test.inclusions=app/code/**/Test/Unit/**/*.php \
-Dsonar.php.coverage.reportPaths=test-reports/phpunit.coverage.xml \
-Dsonar.php.tests.reportPath=test-reports/phpunit.junit.xml \
-Dsonar.branch.name="$(git branch --show-current)"
After realizing it worked locally, I thought that the problem may be with the parameters, so I copied the parameters to the bitbucket pipeline directly and the problem still persisted on the pipeline only.
At this point, I’m not sure where to go from here. Any advice on how to resolve the issue with Bitbucket pipelines would be appreciated