Living in a AI World….

How to Break a Jenkins Build with Sonarqube

in

Last reviewed: July 5, 2026. Applies to: Jenkins builds with SonarQube quality gates and scanner plugins. Currentness note: Commands and screenshots are retained for the documented environment. Before production use, verify package names, image tags, cloud-provider UI labels, and plugin versions against your current platform.

[et_pb_section admin_label=”section”] [et_pb_row admin_label=”row”] [et_pb_column type=”4_4″][et_pb_text admin_label=”Text”]

First, you need SonarQube server 6.2+. In your Jenkins instance, install the latest version of the SonarQube Scanner for Jenkins (2.6.1+). You should, of course, configure in Jenkins administration section the credentials to connect to the SonarQube server.

In your SonarQube server administration page, add a webhook entry:

https://<your Jenkins instance>/sonarqube-webhook/
Jenkins SonarQube quality gate configuration

Now you can configure a pipeline job using the two SonarQube keywords ‘withSonarQubeEnv’ and ‘waitForQualityGate’.

The first one should wrap the execution of the scanner (that will occupy an executor) and the second one will ‘pause’ the pipeline in a very light way, waiting for the webhook payload.

node {
  stage('SCM') {
    git 'https://github.com/foo/bar.git'
  }
  stage('build & SonarQube Scan') {
    withSonarQubeEnv('My SonarQube Server') {
      sh 'mvn clean package sonar:sonar'
    } // SonarQube taskId is automatically attached to the pipeline context
  }
}
 
// No need to occupy a node
stage("Quality Gate") {
  timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
    def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
    if (qg.status != 'OK') {
      error "Pipeline aborted due to quality gate failure: ${qg.status}"
    }
  }
}

Here you are:

Jenkins pipeline stage view with SonarQube checks
SonarQube quality gate result for Jenkins build

That’s all Folks!

[/et_pb_text][/et_pb_column] [/et_pb_row] [/et_pb_section]

Do you have any question, suggestion, or a correction? Do let me know at [email protected]



Follow

Instagram / LinkedIn