title: Sonarqube quality gate stuck on pending when inside jenkins pipeline node
body: <p>We're trying to add a Sonarqube scan as part of our Jenkins pipeline script.
  We have a multi-module maven project,  and we're using the Maven Sonarqube plugin to run the aggregated scan. To initiate the scan we followed the instructions in Sonarqube's documentation as shown <a href="https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline" rel="nofollow noreferrer">here</a> (scroll down to the end of the page).</p>
  <p>So the pipeline script looks something like this :</p>
  <pre><code>node {
      stage('SonarQube analysis') {
          withSonarQubeEnv('My SonarQube Server') {
              sh 'mvn clean package sonar:sonar'
          }
      }
  }
  stage(&quot;Quality Gate&quot;) {
      timeout(time: 1, unit: 'HOURS') { 
          def qg = waitForQualityGate() 
          if (qg.status != 'OK') {
              error &quot;Pipeline aborted due to quality gate failure: ${qg.status}&quot;
          }
      }
  }
  </code></pre>
  <p>and it works as expected. But since we're using it in more than one file, we'd like to have as less duplicate code as possible, so we want to have it inside the node like this :</p>
  <pre><code>node {
      stage('SonarQube analysis') {
          withSonarQubeEnv('My SonarQube Server') {
              sh 'mvn clean package sonar:sonar'
          }
      }
      stage(&quot;Quality Gate&quot;) {
          timeout(time: 1, unit: 'HOURS') { 
              def qg = waitForQualityGate() 
              if (qg.status != 'OK') {
                  error &quot;Pipeline aborted due to quality gate failure: ${qg.status}&quot;
              }
          }
      }
  }
  </code></pre>
  <p>But for some reason, this gets the quality gate stuck on PENDING status until the timeout is reached.
  I'm trying to understand why this is happening, and what could be done to avoid moving the quality gate check outside the node.</p>
  <p>Any help would be greatly appreciated!</p>