Branches and Pull Requests are not visible in SonarQube dashboard?

Viewed 2322

I am using SonarQube's Developer edition (8.4) with GitHub (community edition - not enterprise) to analyze Maven based java projects. I took this sample project and followed all the steps mentioned in this guide to set up.

I have a sample build.yaml file copied from the same tutorial, for a Maven project that looks like below:

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

Whenever a new code is pushed an analysis is done. I can see PR decorations and checks running for PRs as well in github's dashboard.

However, I am not seeing any other branches except master or any Pull Requests in SonarQube's dashboard under Branches & Pull Requests. Below are the screenshots for reference:

Branches (only master branch is visible. I have feature and develop branches too) Branches tab Screenshot

Pull Requests PR Tab screenshot

As per SonarQube's docs, I should be able to see multiple branches and PRs in the dashboard.

Am I missing something?

1 Answers

As a general remark, you should always consult the doc for your specific version. In this case: PR Decoration for SonarQube 8.4.

(According to that doc, if you meant Github.com by "community edition", it should be supported, so nevermind my previous comment.)

The link in the header of this doc page mentions the following keys that should be passed to Maven when running Sonar: sonar.pullrequest.key, sonar.pullrequest.branch, sonar.pullrequest.base.

Example (inspired by here, may need some tweaking):

 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}}
Related