与主分支同步时,Sonarcloud中未显示分支覆盖范围

时间:2019-05-21 11:28:00

标签: java gradle sonarqube jacoco sonarcloud

我正在尝试使用 gradle sonarqube 中的 jacoco 插件对代码进行分析。我的测试是用 Groovy 编写的。我已经使用位桶管道实现了流程自动化,因此,每次我提交代码时,都会运行测试,最后运行jacoco分析和sonarqube,从而将报告结果推送到SonarCloud中。显示覆盖率(以百分比表示,带有指向类的链接),并与dev分支进行比较(我在SonarCloud中将dev明确指定为长期存在的分支)。另外,显示了整体覆盖率(合并后)。

问题是,当我将dev合并到分支中时(其他东西合并到dev中,因此我进行了同步),然后分支覆盖率显示为“-”,即为空。我似乎找不到问题,而不是猜测该提交(来自将dev合并到我的分支中)有两个父级(上一个提交和另一个合并到dev中的短暂分支),并且以某种方式感到困惑。 在我提交了一些内容(甚至是一段愚蠢的代码)之后,分析仍然可以正确地再次显示。

我想知道是否有人解决了这个问题,或者知道为什么会发生。谢谢!

在build.gradle中,我添加了:

 plugins {
    id "org.springframework.boot" version "2.0.2.RELEASE"
    id "org.sonarqube" version "2.7.1"
    id "application"
    id "jacoco"
}

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.8.3"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination file("$buildDir/jacocoHtml")
    }
}

sonarqube {
   properties {
        // properties related to credentials
    }
}

我的bitbucket管道文件是:

image: java:8

clone:
  depth: full  # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - gradle
          - sonar
        script:
          - ./gradlew clean test
          - ./gradlew jacocoTestReport
          - ./gradlew sonarqube
        artifacts:
          - build/libs/**

pipelines:
  default:
    - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

1 个答案:

答案 0 :(得分:1)

在build.gradle中,只需指定jacoco和jacocoTestReport属性即可,如下所示:

// Update SiB contact hourly
function sendinblue_update() {
  global $wpdb;

  $customer_data = $wpdb->get_results("SELECT * FROM imp_customer_log WHERE updated_in_sib = '0'");
    foreach( $customer_data as $customer ) {

        $customer_id = $customer->customer_id;
    $customer_event = $customer->event;
    $customer_data = $customer->data;

        $user = get_user_by( 'id', $customer_id );
        $user_email = $user->user_email;

        $data_in = array(
            $customer_event => $customer_data,
        );
        $result = $this->sendinblue_update_user($user_email, $data_in);

        $wpdb->update('imp_customer_log', ['updated_in_sib' => 1], ['customer_id' => $customer_id]);

  }

}

然后在bitbucket-pipelines.yml中,执行以下操作:

jacoco {
    toolVersion = "0.8.3"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled true
        csv.enabled false
        html.destination file("$buildDir/customJacocoReportDir/test/html")
        xml.destination file("$buildDir/customJacocoReportDir/test/jacocoTestReport.xml")
    }
}

sonarqube {
    properties {
        // define your properties
        property "sonar.jacoco.reportPath", "$buildDir/jacoco/test.exec"
        property "sonar.coverage.jacoco.xmlReportPaths", "$buildDir/customJacocoReportDir/test/jacocoTestReport.xml"
    }
}