首页 > 解决方案 > 分支和拉取请求在 SonarQube 仪表板中不可见?

问题描述

我正在使用 SonarQube 的开发人员版(8.4)和 GitHub(社区版 - 非企业版)来分析基于 Maven 的 java 项目。我采用了这个示例项目,并按照本指南中提到的所有步骤进行设置。

我有一个从同一教程复制的示例 build.yaml 文件,用于 Maven 项目,如下所示:

name: Build
on:
  push:
    branches:
      - master
      - develop
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: Cache SonarQube packages
        uses: actions/cache@v1
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Cache Maven packages
        uses: actions/cache@v1
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2
      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
        run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

每当推送新代码时,都会进行分析。我也可以在 github 的仪表板中看到 PR 装饰和检查 PR。

master但是,除了SonarQube 仪表板中的Branches & Pull Requests下的任何 Pull Requests之外,我没有看到任何其他分支。以下是截图供参考:

分支(只有主分支可见。我也有功能和开发分支) 分支选项卡屏幕截图

拉取请求 PR 标签截图

根据 SonarQube 的文档,我应该能够在仪表板中看到多个分支和 PR。

我错过了什么吗?

标签: gitmavengithubsonarqube

解决方案


一般来说,您应该始终查阅文档以了解您的特定版本。在这种情况下:SonarQube 8.4 的 PR 装饰

(根据该文档,如果您通过“社区版”指的是 Github.com,则应该支持它,所以不要介意我之前的评论。)

此文档页面标题中的链接提到了在运行 Sonar 时应传递给 Maven 的以下键:sonar.pullrequest.keysonar.pullrequest.branchsonar.pullrequest.base

示例(受此处启发,可能需要一些调整):

 mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.pullrequest.key=${{github.event.pull_request.number}}

推荐阅读