git - 分支和拉取请求在 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之外,我没有看到任何其他分支。以下是截图供参考:
根据 SonarQube 的文档,我应该能够在仪表板中看到多个分支和 PR。
我错过了什么吗?
解决方案
一般来说,您应该始终查阅文档以了解您的特定版本。在这种情况下:SonarQube 8.4 的 PR 装饰。
(根据该文档,如果您通过“社区版”指的是 Github.com,则应该支持它,所以不要介意我之前的评论。)
此文档页面标题中的链接提到了在运行 Sonar 时应传递给 Maven 的以下键:sonar.pullrequest.key
、sonar.pullrequest.branch
、sonar.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}}
推荐阅读
- angular5 - Angular5 模板驱动的跨字段异步验证器
- angular - 加载后数组上的 ngFor
- javascript - 承诺与多重决心
- binary - 用虚拟 X 取线性回归中 Y 变量的比率
- go - 提供 -coverpkg 参数时 go test 失败
- javascript - 用于动态选项卡的 ajax
- powerbi - 我们可以在另一个 DAX 公式中删除 DAX 过滤器吗?
- cors - 带有查询参数的路径上顶点中的 Cors
- javascript - 自定义 JS 仅适用于分页项目的第一页
- javascript - 如何在函数中执行 2 个 firebase 查询以检索数据反应原生