What is a quality gate in a CI/CD pipeline?
BeginnerConceptCI/CD practices
Answer
In one line: A quality gate is an automatic checkpoint in the pipeline that stops the code from moving forward unless it meets agreed standards — such as all tests passing, enough test coverage, or no critical vulnerabilities.
Common quality gates:
- Build and unit tests pass.
- Code coverage above a threshold (for example 80% on new code).
- Static code analysis — SonarQube quality gate: no new bugs, code smells or security hotspots above a limit.
- Security scans — no critical/high vulnerabilities in dependencies (SCA) or container images; no secrets found.
- IaC policy checks — Checkov or OPA rules pass (no public S3 buckets, encryption on).
- Integration / end-to-end tests pass in the test environment.
- Performance — response time under an agreed limit in a load test.
- Manual approval — for production, when required.
How it blocks the pipeline: the step returns a non-zero exit code, so the job fails and later stages don't run.
# Fail if any critical vulnerability is found
trivy image --severity CRITICAL --exit-code 1 orders:1.4.2
In SonarQube, the scanner can wait for the quality gate result and fail the build if it's red.
Good practices:
- Gate on new code, not the whole legacy codebase — otherwise old problems block every change.
- Start soft, then strict — report-only at first, then block once the team has cleaned up.
- Keep gates fast so developers get feedback quickly.
- Allow documented exceptions for false positives, with an owner and an expiry date.
Example: a team's PR pipeline blocks merges if unit tests fail, coverage on new code is below 80%, or Trivy finds a critical CVE with a fix available.
Tip for interviews: say which gates you set, the thresholds, and how you handled false positives.
More on CI/CD practices
What is "pipeline as code", and why is it better than configuring pipelines in a UI?BeginnerWhat is a build agent or runner?BeginnerWhat are pipeline triggers?BeginnerHow do you make a slow CI/CD pipeline faster?BeginnerWhat are secrets in CI/CD, and how should they be handled?BeginnerWhat is a monorepo vs a polyrepo, and how does it affect CI/CD?Beginner