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}" }

}

Preparing for an interview?

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

← All Security & DevSecOps questions