Quality Gate Definition
Build automated gates that catch issues before review, enabling faster async review cycles.
Context
You are helping a tech lead design CI/CD quality gates. If you have access to project structure, tech stack, or known defects, use them to ground gate recommendations.
Domain Context
- SonarQube and similar tools: automated quality gates catch 60-70% of defects that code review would catch, but faster
- CI/CD best practice: gates should fail fast (< 5 minutes) or they get bypassed
- Research: teams that use automated gates spend 30-40% less time in code review
Key principles:
- Fail fast or fail never: Gates that take 20 minutes are skipped. Keep gates under 5 minutes
- Be specific, not broad: "Code quality" is vague. "Cyclomatic complexity > 10" is actionable
- Gates should be gating, not advisory: If a gate fails, the PR cannot merge. Advisory warnings (yellow builds) get ignored
- Gates evolve with team maturity: A junior team might allow 80% coverage; a mature team might enforce 90%
Instructions
Define gate categories:
- Style (linter, formatter) — autofix or block
- Testing (coverage, execution) — block if below threshold
- Performance (build time, artifact size) — block if regresses > 10%
- Security (dependency audit, secrets scan) — block on high severity
- Architecture (complexity, dependency rules) — block on violations
- Accessibility (for web/UI) — block on critical issues
For each gate, set thresholds:
- Coverage: block if drops below 80% (or your team standard)
- Linter: block on any errors (warnings can be advisory)
- Build time: block if > 10% slower than baseline
- Artifact size: block if > 5% larger
- Security: block on high/critical, warn on medium
- Complexity: block if cyclomatic complexity > 10 or > 3 nesting depth
Create bypass criteria: Emergency/hotfix PRs can bypass some gates if explicitly labeled. Document which gates can bypass and who approves
Test the gates: Run gates against your main branch. If they fail there, they're broken. Fix gates before enforcing
Make gates visible: Show results in PR comments, not just build status. Developers should see exactly why a gate failed
Measure false positives: If more than 20% of gate failures are overridden, the gate is miscalibrated. Lower threshold or remove gate
Example gate configuration:
Linter: block on errors, warn on > 5 warnings
Coverage: block if drops > 2%, advisory if drops 0-2%
Build time: advisory if > 10% slower, block if > 30% slower
Secrets: block on any leaked secrets
Dependencies: block on high/critical CVEs
Performance: advisory if bundle > 1MB, block if > 2MB
Anti-Patterns
- Gates that take forever: LLMs sometimes recommend running full test suites, security scans, and load tests in gates. If it takes 20 minutes, developers will bypass. Keep gates fast
- Gates without remediation paths: "Code quality too low" without saying how to fix it is frustrating. Always include "why" and "how to fix" in gate failure messages
- Too many gates: Teams with 15+ gates have slower CI and more bypasses. Focus on gates that catch high-impact issues (security, critical bugs, performance)
- Gates that don't match reality: LLMs sometimes recommend coverage thresholds your team can't achieve with existing code. Start with current reality, then increase
Further Reading
- SonarQube documentation: comprehensive guide to quality gates and thresholds.
- Kim, Gene et al. "The DevOps Handbook." IT Revolution Press, 2016. Chapter on continuous delivery practices.
- Forsgren, Nicole et al. "Accelerate." IT Revolution Press, 2018. Chapter on deployment frequency and automation.
1---2name: quality-gate-definition3description: Define automated quality gates that enforce standards without manual review. Use when setting up CI/CD checks and blocking criteria.4---56# Quality Gate Definition78Build automated gates that catch issues before review, enabling faster async review cycles.910## Context1112You are helping a tech lead design CI/CD quality gates. If you have access to project structure, tech stack, or known defects, use them to ground gate recommendations.1314## Domain Context1516- SonarQube and similar tools: automated quality gates catch 60-70% of defects that code review would catch, but faster17- CI/CD best practice: gates should fail fast (< 5 minutes) or they get bypassed18- Research: teams that use automated gates spend 30-40% less time in code review1920Key principles:21221. **Fail fast or fail never**: Gates that take 20 minutes are skipped. Keep gates under 5 minutes232. **Be specific, not broad**: "Code quality" is vague. "Cyclomatic complexity > 10" is actionable243. **Gates should be gating, not advisory**: If a gate fails, the PR cannot merge. Advisory warnings (yellow builds) get ignored254. **Gates evolve with team maturity**: A junior team might allow 80% coverage; a mature team might enforce 90%2627## Instructions28291. **Define gate categories**:30 - Style (linter, formatter) — autofix or block31 - Testing (coverage, execution) — block if below threshold32 - Performance (build time, artifact size) — block if regresses > 10%33 - Security (dependency audit, secrets scan) — block on high severity34 - Architecture (complexity, dependency rules) — block on violations35 - Accessibility (for web/UI) — block on critical issues36372. **For each gate, set thresholds**:38 - Coverage: block if drops below 80% (or your team standard)39 - Linter: block on any errors (warnings can be advisory)40 - Build time: block if > 10% slower than baseline41 - Artifact size: block if > 5% larger42 - Security: block on high/critical, warn on medium43 - Complexity: block if cyclomatic complexity > 10 or > 3 nesting depth44453. **Create bypass criteria**: Emergency/hotfix PRs can bypass some gates if explicitly labeled. Document which gates can bypass and who approves46474. **Test the gates**: Run gates against your main branch. If they fail there, they're broken. Fix gates before enforcing48495. **Make gates visible**: Show results in PR comments, not just build status. Developers should see exactly why a gate failed50516. **Measure false positives**: If more than 20% of gate failures are overridden, the gate is miscalibrated. Lower threshold or remove gate5253Example gate configuration:5455```56Linter: block on errors, warn on > 5 warnings57Coverage: block if drops > 2%, advisory if drops 0-2%58Build time: advisory if > 10% slower, block if > 30% slower59Secrets: block on any leaked secrets60Dependencies: block on high/critical CVEs61Performance: advisory if bundle > 1MB, block if > 2MB62```6364## Anti-Patterns6566- **Gates that take forever**: LLMs sometimes recommend running full test suites, security scans, and load tests in gates. If it takes 20 minutes, developers will bypass. Keep gates fast67- **Gates without remediation paths**: "Code quality too low" without saying how to fix it is frustrating. Always include "why" and "how to fix" in gate failure messages68- **Too many gates**: Teams with 15+ gates have slower CI and more bypasses. Focus on gates that catch high-impact issues (security, critical bugs, performance)69- **Gates that don't match reality**: LLMs sometimes recommend coverage thresholds your team can't achieve with existing code. Start with current reality, then increase7071## Further Reading7273- SonarQube documentation: comprehensive guide to quality gates and thresholds.74- Kim, Gene et al. "The DevOps Handbook." IT Revolution Press, 2016. Chapter on continuous delivery practices.75- Forsgren, Nicole et al. "Accelerate." IT Revolution Press, 2018. Chapter on deployment frequency and automation.