Skip to main content

Quality Gates

Quality gates are sets of conditions that a project must meet to be considered "production ready." Bob the Fixer uses quality gates to determine if your code passes or fails quality checks.

Understanding Quality Gates

A quality gate evaluates your code against defined thresholds:

QUALITY GATE STATUS

Status: ❌ **FAILED**

CONDITIONS:

✗ **new_bugs**
- Comparator: LT (less than)
- Actual Value: 3
- Error Threshold: 1
- Status: ERROR

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

Built-in Templates

Bob the Fixer provides three quality gate templates:

Strict Template

Zero tolerance for quality issues. Best for production-ready code.

MetricConditionThreshold
New BugsLess than1
New VulnerabilitiesLess than1
New Code SmellsLess than1
New CoverageGreater than80%
New DuplicationLess than3%

Use when:

  • Deploying to production
  • Building security-critical applications
  • Working on financial or healthcare software

Balanced Template (Default)

Reasonable thresholds for most projects.

MetricConditionThreshold
New BugsLess than1
New VulnerabilitiesLess than1
New Blocker IssuesLess than1
New Critical IssuesLess than1
New CoverageGreater than60%
New DuplicationLess than5%

Use when:

  • Standard development workflow
  • Most enterprise applications
  • Team projects with code review

Permissive Template

Relaxed rules for legacy or experimental code.

MetricConditionThreshold
New Blocker IssuesLess than1
New Critical IssuesLess than5
New DuplicationLess than10%

Use when:

  • Working with legacy codebases
  • Rapid prototyping
  • Gradual quality improvement

Setting Quality Gates

During Auto-Setup

Set up this project with a strict quality gate

Uses sonar_auto_setup with template: "strict".

In Configuration

Add to your bobthefixer.env:

SONAR_QUALITY_GATE=strict

Via MCP Tool

{
"template": "strict",
"force": true
}

Checking Quality Gate Status

Via AI Assistant

Check if my project passes the quality gate

Uses sonar_get_quality_gate tool.

Response Format

QUALITY GATE STATUS

Status: ✅ **PASSED**

CONDITIONS:

✓ **new_bugs**
- Actual Value: 0
- Error Threshold: 1
- Status: OK

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

✓ **new_coverage**
- Actual Value: 75.5
- Error Threshold: 60
- Status: OK

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

Clean as You Code Status: COMPLIANT

Quality Metrics Explained

Bug Metrics

MetricDescription
bugsTotal bugs in all code
new_bugsBugs in new/changed code only
reliability_ratingA-E rating based on bugs

Vulnerability Metrics

MetricDescription
vulnerabilitiesTotal security vulnerabilities
new_vulnerabilitiesVulnerabilities in new code
security_ratingA-E rating based on vulnerabilities

Code Smell Metrics

MetricDescription
code_smellsTotal maintainability issues
new_code_smellsCode smells in new code
sqale_ratingA-E maintainability rating

Coverage Metrics

MetricDescription
coverageOverall test coverage %
new_coverageCoverage of new code
line_coverageLines covered by tests
branch_coverageBranches covered by tests

Duplication Metrics

MetricDescription
duplicated_lines_density% of duplicated code
new_duplicated_lines_densityDuplication in new code
duplicated_blocksNumber of duplicate blocks

Clean as You Code

Bob the Fixer follows SonarQube's "Clean as You Code" methodology:

  1. Focus on new code - Don't get overwhelmed by existing issues
  2. Set clear standards - Define what "clean" means for your project
  3. Fail fast - Catch issues before they merge

Quality gates primarily evaluate new code to:

  • Prevent new issues from entering the codebase
  • Allow gradual cleanup of legacy code
  • Keep the feedback loop tight

Customizing Quality Gates

In SonarQube UI

  1. Open http://localhost:9000
  2. Go to Quality Gates
  3. Create or copy an existing gate
  4. Add/modify conditions
  5. Set as default for your project

Condition Operators

OperatorMeaningExample
LTLess thanbugs LT 1 (must have 0 bugs)
GTGreater thancoverage GT 80 (must have >80%)
EQEqualsRarely used
NENot equalsRarely used

Best Practices

Starting a New Project

  1. Use Strict template
  2. Configure CI to fail on quality gate failure
  3. Review and fix issues before merging

Improving Legacy Code

  1. Start with Permissive template
  2. Track metrics over time
  3. Gradually tighten thresholds
  4. Focus on new code first

Team Guidelines

PracticeRecommendation
PR ChecksBlock merge on quality gate failure
CoverageRequire tests for new code
ReviewsUse issue reports in code review
MonitoringTrack quality metrics in dashboards

Troubleshooting

"Quality gate not found"

Ensure the project has been scanned at least once:

Scan this project with autoSetup: true

"No data for quality gate"

Quality gates need analysis data. Run a scan first:

Scan this project and then check the quality gate

Gate always failing

Check which conditions are failing:

Which quality gate conditions are failing?

Then address the specific metrics:

  • Coverage: Add more tests
  • Bugs: Fix detected issues
  • Duplication: Refactor duplicate code

Next Steps