Jenkins PHP Unit Test and Code Coverage unable to import in SonarQube

℡╲_俬逩灬. 提交于 2021-02-11 15:37:16

问题


I have been struggling with importing unit test results and code coverage from Jenkins into SonarQube. At this point, I have verified the results are being generated as they are displayed in the project's page in Jenkins.

The sonar.properties file is shown below. The php results were created with phpunit and the code coverage was created with phpunit and clover. As an effort in troubleshooting, I included both sonar.php.coverage.reportPath and sonar.clover.reportPath.

sonar.projectKey=projectKey
sonar.projectName=projectKey
sonar.projectVersion=1.0
sonar.language=php
sonar.sourceEncoding=UTF-8

sonar.php.tests.reportPath=report/phpunitresults.xml
sonar.php.coverage.reportPath=report/clover_code_coverage.xml
sonar.clover.reportPath=report/clover_code_coverage.xml 

sonar.sources=./src/
sonar.exclusions=./src/tests/**
sonar.tests=./src/tests/
sonar.coverage.exclusions=./src/tests/**/*.php

All of the results Unit Tests Coverage 0.0% Line Coverage 0.0%

The Jenkins builds do not produce any errors or helpful information in identifying a problem as to why the results are not being imported.

Can anyone help in troubleshooting the issue?

Thanks.

  • Ben

回答1:


My problem was that coverage reports were generated on server different from where sonar-scanner was run, and the absolute paths in clover.xml differed.

Solution was to fix the paths:

replace="s|/home/bamboo/project/|`pwd`/|g"
sed -i -- $replace report/*.xml


来源:https://stackoverflow.com/questions/31840022/jenkins-php-unit-test-and-code-coverage-unable-to-import-in-sonarqube

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!