Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-pull-request

GitHub Action

SonarQube Quality Gate Report

v1.3.2

SonarQube Quality Gate Report

git-pull-request

SonarQube Quality Gate Report

Retrieve quality gate result of an analysis

Installation

Copy and paste the following snippet into your .yml file.

              

- name: SonarQube Quality Gate Report

uses: phwt/[email protected]

Learn more about this action in phwt/sonarqube-quality-gate-action

Choose a version

SonarQube Quality Gate Check

Check quality gate result from latest analysis and report result in the pull request's comment.

PR comment

Inputs

Input Description Default Required
sonar-project-key SonarQube project key true
sonar-host-url SonarQube server URL true
sonar-token SonarQube token for retrieving quality gate result true
github-token GitHub Token for commenting on the pull request - not required if disable-pr-comment is set to true false
disable-pr-comment Disable commenting result on the pull request false false
fail-on-quality-gate-error Set the action status to failed when quality gate status is ERROR false false

Outputs

Output Description
project-status Project's quality gate status either as OK or ERROR
quality-gate-result Quality gate result of the latest analysis in JSON format

Usage example

name: Check quality gate result on pull request

on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: phwt/sonarqube-quality-gate-action@v1
        id: quality-gate-check
        with:
          sonar-project-key: ${{ secrets.SONAR_PROJECT_KEY }}
          sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
          sonar-token: ${{ secrets.SONAR_TOKEN }}
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Output result
        run: |
          echo "${{ steps.quality-gate-check.outputs.project-status }}"
          echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}"

Check the results immediately after the scan

Sometimes the results will not be available right away after the scan has finished. Make sure to add a defer step before retrieving the scan results.

name: Check quality gate result on pull request

on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: some/scan-actions@v1 # Step for scanning your project

      - name: Wait for the quality gate result
        run: sleep 5

      - uses: phwt/sonarqube-quality-gate-action@v1
        id: quality-gate-check
        with:
          sonar-project-key: ${{ secrets.SONAR_PROJECT_KEY }}
          sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
          sonar-token: ${{ secrets.SONAR_TOKEN }}
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Output result
        run: |
          echo "${{ steps.quality-gate-check.outputs.project-status }}"
          echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}"