Interview › Security & DevSecOps
What is a SonarQube quality gate, and how do you use it to fail a build? [Basic]
Answer
A SonarQube quality gate is a set of pass/fail conditions applied to an analysis result. In CI, I use it to fail the build or block a merge when new code violates defined thresholds such as new vulnerabilities, coverage, bugs, or duplication.
Technical explanation
Quality gates are most effective when focused on new code, because legacy projects can adopt them without being blocked by old debt on day one.
The CI job submits analysis, waits for the quality gate result, and returns a nonzero status if the gate fails.
Typical conditions include zero new critical vulnerabilities, minimum new-code coverage, acceptable duplication, and no blocker bugs.
Hands-on example
Jenkins example:
withSonarQubeEnv('sonarqube') { sh 'mvn clean verify sonar:sonar' }
timeout(time: 5, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') { error "Quality gate failed: ${qg.status}" }
}Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Security & DevSecOps interview questions
- Is SonarQube primarily SAST, code quality, or both? [Basic]
- What is the difference between a quality gate and a quality profile in SonarQube? [Basic]
- What does 'clean as you code' mean in SonarQube, and why focus on new code? [Basic]
- What is software composition analysis (SCA), and why does it matter for dependencies? [Basic]
- What metrics does SonarQube track (coverage, duplication, code smells, bugs, vulnerabilities)? [Basic]
- What is technical debt in SonarQube, and how is it estimated? [Basic]
- How does SonarQube measure code coverage, and does it run your tests? [Basic]
- What is a SonarQube hotspot, and how is it different from a vulnerability? [Basic]