SonarQube PHP没有代码覆盖

时间:2015-06-18 09:46:06

标签: php jenkins sonarqube sonar-runner sonarqube-5.0

我们正在使用jenkins和SonarQube对我们的php项目进行代码分析。我们现在在不同的服务器上生成phpunit覆盖文件,并希望将这些覆盖文件加载到SonarQube中。问题是覆盖文件在那里,似乎在SonarQube中加载,但SonarQube中的代码覆盖率仍然是空的。有趣的是加载代码覆盖文件后的行:

INFO  - Project: null

在这篇文章中,旧的声纳邮件列表中描述了同样的错误: http://sonarqube.15.x6.nabble.com/PHPUnit-test-coverage-from-PHPUnit-not-being-picked-up-with-Giving-Project-null-error-tc5028771.html#none

全跑者日志:

INFO: Runner configuration file: /opt/sonar-runner/conf/sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /var/lib/jenkins/jobs/FooBarJob-Dev/workspace/.sonar
INFO: SonarQube Server 5.0
INFO  - Load global referentials...
INFO  - Load global referentials done: 297 ms
INFO  - User cache: /var/lib/jenkins/.sonar/cache
INFO  - Install plugins
INFO  - Install JDBC driver
INFO  - Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
INFO  - Initializing Hibernate
INFO  - Load project referentials...
INFO  - Load project referentials done: 1514 ms
INFO  - Load project settings
INFO  - Loading technical debt model...
INFO  - Loading technical debt model done: 30 ms
INFO  - Apply project exclusions
INFO  - -------------  Scan FooBarJob
INFO  - Load module settings
INFO  - Language is forced to php
INFO  - Loading rules...
INFO  - Loading rules done: 1442 ms
INFO  - Configure Maven plugins
INFO  - Compare to previous analysis (2015-06-18)
INFO  - Compare over 30 days (2015-05-19, analysis of 2015-06-18 08:18:26.0)
INFO  - No quality gate is configured.
INFO  - Base dir: /var/lib/jenkins/jobs/FooBarJobDev/workspace
INFO  - Working dir: /var/lib/jenkins/jobs/FooBarJob-Dev/workspace/.sonar
INFO  - Source paths: src/main
INFO  - Test paths: src/main/php/FooBarJob/Tests
INFO  - Source encoding: UTF-8, default locale: en_US
INFO  - Index files
INFO  - Excluded sources: 
INFO  -   **/Tests/**
INFO  -   **/Tests/**
INFO  - Included tests: 
INFO  -   **/Tests/**
INFO  - 48 files indexed
INFO  - Quality profile for php: Sonar way
INFO  - Sensor NoSonar and Commented out LOC Sensor...
INFO  - Sensor NoSonar and Commented out LOC Sensor done: 156 ms
INFO  - Sensor QProfileSensor...
INFO  - Sensor QProfileSensor done: 6 ms
INFO  - Sensor org.sonar.plugins.php.PHPSquidSensor@118b47dc...
INFO  - Sensor org.sonar.plugins.php.PHPSquidSensor@118b47dc done: 1984 ms
INFO  - Sensor PHPUnit Sensor...
INFO  - Analyzing PHPUnit tests report: var/phpunit.xml
INFO  - Analyzing PHPUnit coverage report: var/coverage.xml
INFO  - Project: null
INFO  - Sensor PHPUnit Sensor done: 1507 ms
INFO  - Sensor InitialOpenIssuesSensor...
INFO  - Sensor InitialOpenIssuesSensor done: 127 ms
INFO  - Sensor ProjectLinksSensor...
INFO  - Sensor ProjectLinksSensor done: 15 ms
INFO  - Sensor VersionEventsSensor...
INFO  - Sensor VersionEventsSensor done: 40 ms
INFO  - Sensor FileHashSensor...
INFO  - Sensor FileHashSensor done: 114 ms
INFO  - Sensor SCM Sensor...
INFO  - Sensor SCM Sensor done: 125 ms
INFO  - Sensor CPD Sensor...
INFO  - DefaultCpdEngine is used for php
INFO  - Cross-project analysis disabled
INFO  - Sensor CPD Sensor done: 373 ms
INFO  - Execute decorators...
INFO  - Store results in database
INFO  - ANALYSIS SUCCESSFUL, you can browse https://localhost/sonar/dashboard/index/com.barComp:FooBarJob
INFO  - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.
INFO  - Executing post-job class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob

1 个答案:

答案 0 :(得分:2)

coverage文件包含源文件的路径,这些路径应该是绝对路径。如果您在一台服务器上生成phpunit coverage文件并在另一台服务器上启动SonarQube分析,则绝对路径很可能会有所不同。加载coverage文件时无法解析的路径将被忽略。

还有一件事:最新版本的SonarQube PHP插件(2.6)为您提供了对这类问题更有帮助的日志。