Using waitForQualityGate in a Jenkins declarative pipeline Using waitForQualityGate in a Jenkins declarative pipeline jenkins jenkins

Using waitForQualityGate in a Jenkins declarative pipeline


The SonarQube Jenkins plugin scans the build output for two specific lines, which it uses to get the SonarQube report task properties and project URL. If your invocation of sonar-scanner does not output these lines, the waitForQualityGate() call won't have the task ID to look them up. So you will have to figure out the correct settings to make it more verbose.

See the extractSonarProjectURLFromLogs and extractReportTask methods in the SonarUtils class of the plugin to understand how they work:

  • ANALYSIS SUCCESSFUL, you can browse <project URL> is used to add a link to the badge (in the build history)
  • Working dir: <dir with report-task.txt> is used to pass the task ID to the waitForQualityGate step


This was discovered to be a bug in the SonarQube scanner for Jenkins, when using a Jenkins slave for jobs (if the job is run on the master, it'd work). You can read more here: https://jira.sonarsource.com/browse/SONARJNKNS-282

I have tested this using a test build of v2.61 of the scanner plug-in and found it working.The solution is to upgrade to v2.61 when released.

This stage will then work:

stage ("SonarQube analysis") {   steps {      withSonarQubeEnv('SonarQube') {         sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"         }      def qualitygate = waitForQualityGate()      if (qualitygate.status != "OK") {         error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"      }   }}


If you're running SonarCube in a docker container check that the memory isn't exhausted. We were maxing out. Which seemed to be the issue.