Skip to content

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

License

Notifications You must be signed in to change notification settings

nosinovacao/sonarqube-quality-gate-action

 
 

Repository files navigation

SonarQube Quality Gate Check

Quality Gate Status

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

PR comment

Inputs

parameter description required default
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
branch Branch name to retrieve the quality gate result false

Outputs

parameter description
project-status Project's quality gate status either as OK or ERROR
quality-gate-result Quality gate 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 }}
          branch: main # Optional input

      - 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 }}
          branch: main # Optional input

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.5%
  • Dockerfile 0.5%