title: Using waitForQualityGate in a Jenkins declarative pipeline
body: <p>The following SonarQube (6.3) analysis stage in a declarative pipeline in Jenkins 2.50 is failing with this error in the console log: <a href="http://pastebin.com/t2ja23vC" rel="noreferrer">http://pastebin.com/t2ja23vC</a>. More specifically:</p>
  
  <blockquote>
    <p>SonarQube installation defined in this job (SonarGate) does not match any configured installation. Number of installations that can be configured: 1.</p>
  </blockquote>
  
  <p><strong>Update:</strong> after changing "SonarQube" to "SonarGate" in the Jenkins settings (under SonarQube servers, so it'll match the Jenkinsfile), I get a different error: <a href="http://pastebin.com/HZZ6fY6V" rel="noreferrer">http://pastebin.com/HZZ6fY6V</a></p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.</p>
  </blockquote>
  
  <hr>
  
  <p>The stage is a modification of the example from the SonarQube docs: <a href="https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline" rel="noreferrer">https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline</a></p>
  
  <pre><code>stage ("SonarQube analysis") {
       steps {
          script {
             STAGE_NAME = "SonarQube analysis"
  
             if (BRANCH_NAME == "develop") {
                echo "In 'develop' branch, don't analyze."
             }
             else { // this is a PR build, run sonar analysis
                withSonarQubeEnv("SonarGate") {
                   sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"   
                }
             }
          }
       }
    }
  
    stage ("SonarQube Gatekeeper") {
       steps {
          script {
             STAGE_NAME = "SonarQube Gatekeeper"
  
             if (BRANCH_NAME == "develop") {
                echo "In 'develop' branch, skip."
             }
             else { // this is a PR build, fail on threshold spill
                def qualitygate = waitForQualityGate()
                if (qualitygate.status != "OK") {
                   error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
                } 
             }
          }
       }
    }     
  </code></pre>
  
  <p>I also created a webhook, <code>sonarqube-webhook</code>, with the URL <code>http://****/sonarqube-webhook/</code>. Should it be like that, or <code>http://****/sonarqube/sonarqube-webhook</code>? To access the server dashboard I use <code>http://****/sonarqube</code>.</p>
  
  <p>In SonarQube's Quality Gates section I created a new quality gate:</p>
  
  <p><a href="https://i.stack.imgur.com/egOGh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/egOGh.png" alt="enter image description here"></a></p>
  
  <p>I am not sure if the setting in SonarGate is correct. I do use jenkins-mocha to generate an lcov.info file that is used in Sonar to generate the coverage data.</p>
  
  <p>Perhaps the quality gate setting is the wrong setting to do? The end result is to fail the job in Jenkins if coverage % is not met.</p>
  
  <p><a href="https://i.stack.imgur.com/6zpdz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6zpdz.png" alt="enter image description here"></a></p>
  
  <p>Finally, I am not sure if the following configurations in the Jenkins system configuration are at all required:</p>
  
  <p><a href="https://i.stack.imgur.com/74lkb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/74lkb.png" alt="enter image description here"></a></p>
  
  <p>And</p>
  
  <p>(It's 9000 not 900... cut text in the screen shot)
  <a href="https://i.stack.imgur.com/j3jIb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/j3jIb.png" alt="enter image description here"></a></p>