Check quality gate result from latest analysis and report result in the pull request's comment.
This action replicates the action in this repo but was adapted to work on Linux, MacOS and Windows.
| 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 |
| 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 |
name: Check quality gate result on pull request
on:
pull_request:
jobs:
test:
runs-on: windows-latest
steps:
- uses: DesarrolloORT/sonarqube-quality-gate-action@v2
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 }}"The action now includes automatic retry logic to handle timing issues when SonarQube is still processing the analysis. If the results are not yet available, the action will:
- Detect when the analysis is incomplete (all values are N/A)
- Automatically wait and retry with exponential backoff
- Maximum of 5 retries with progressive delays:
- 1st attempt: immediate
- 2nd attempt: wait 2 seconds
- 3rd attempt: wait 4 seconds
- 4th attempt: wait 8 seconds
- 5th attempt: wait 16 seconds
This eliminates the need for manual retry runs or sleep steps in most cases. The action will automatically get the results once SonarQube has finished processing.
name: Check quality gate result on pull request
on:
pull_request:
jobs:
test:
runs-on: windows-latest
steps:
- uses: some/scan-actions@v2 # Step for scanning your project
# The action now handles waiting automatically! ✨
- uses: DesarrolloORT/sonarqube-quality-gate-action@v2
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 }}"If you prefer to add an explicit wait before the action runs, you can still do so:
name: Check quality gate result on pull request
on:
pull_request:
jobs:
test:
runs-on: windows-latest
steps:
- uses: some/scan-actions@v2 # Step for scanning your project
- name: Wait for the quality gate result (optional)
run: sleep 5
- uses: DesarrolloORT/sonarqube-quality-gate-action@v2
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 }}"