Skip to main content

sonar_get_quality_gate

Check quality gate status and get recommendations.

Description

Returns the pass/fail status of the project's quality gate along with details about which conditions passed or failed. Essential for CI/CD integration and release readiness checks.

Parameters

This tool takes no parameters.

Usage

Did we pass the quality gate?

Tool call:

{}

Response Format

Passing Quality Gate

QUALITY GATE STATUS
━━━━━━━━━━━━━━━━━━━

Status: ✅ PASSED

CONDITIONS:

✓ new_bugs
- Comparator: LT (less than)
- Actual Value: 0
- Error Threshold: 1
- Status: OK

✓ new_vulnerabilities
- Comparator: LT
- Actual Value: 0
- Error Threshold: 1
- Status: OK

✓ new_coverage
- Comparator: GT (greater than)
- Actual Value: 75.5
- Error Threshold: 60
- Status: OK

✓ new_duplicated_lines_density
- Comparator: LT
- Actual Value: 2.1
- Error Threshold: 5
- Status: OK

PERIOD:
Mode: REFERENCE_BRANCH
Date: 2024-01-15

Clean as You Code Status: COMPLIANT

Failing Quality Gate

QUALITY GATE STATUS
━━━━━━━━━━━━━━━━━━━

Status: ❌ FAILED

CONDITIONS:

✗ new_coverage
- Comparator: GT (greater than)
- Actual Value: 45.2
- Error Threshold: 60
- Status: ERROR
⚠️ Need 14.8% more coverage

✗ new_bugs
- Comparator: LT (less than)
- Actual Value: 3
- Error Threshold: 1
- Status: ERROR
⚠️ Fix 2 more bugs

✓ new_vulnerabilities
- Comparator: LT
- Actual Value: 0
- Error Threshold: 1
- Status: OK

PERIOD:
Mode: REFERENCE_BRANCH
Date: 2024-01-15

RECOMMENDATIONS:
1. Add tests to increase coverage to 60%
2. Fix 3 new bugs introduced in this branch

Condition Comparators

ComparatorMeaningExample
LTLess thanbugs LT 1 = must have 0 bugs
GTGreater thancoverage GT 60 = must exceed 60%
EQEqualsRarely used
NENot equalsRarely used

Examples

Example 1: Release Check

Prompt:

Can we release? Check the quality gate

Tool Call:

{}

Example 2: PR Validation

Prompt:

Does my PR pass quality checks?

Tool Call:

{}

Quality Gate Conditions

Common conditions in quality gates:

ConditionTypical ThresholdPurpose
new_bugs< 1No new bugs
new_vulnerabilities< 1No new security issues
new_blocker_violations< 1No blockers
new_critical_violations< 1No criticals
new_coverage> 60-80%Maintain coverage
new_duplicated_lines_density< 3-5%Limit duplication

Period Modes

ModeDescription
REFERENCE_BRANCHCompares to main branch
PREVIOUS_VERSIONCompares to last version
DATECompares to specific date
NUMBER_OF_DAYSCompares to N days ago

Best Practices

  1. Block on failure - Don't deploy failing builds
  2. Fix before merge - Quality gate guards the main branch
  3. Review conditions - Ensure thresholds are appropriate
  4. Track trends - Consistent failures indicate systemic issues

Common Issues

"Quality gate not computed"

Cause: Analysis hasn't completed or no quality gate assigned.

Solution: Run sonar_scan_project and ensure quality gate is assigned.

"All conditions pass but gate fails"

Cause: Hidden conditions or server-side rules.

Solution: Check SonarQube UI for full condition list.