title: Quality Gate does not fail when conditions for success are not met
body: <p>I have established Quality Gate for my Jenkins project via SonarQube. One of my projects have no tests at all, so in the analysis I see that the code coverage is 0%. By the quality gate rules (&lt;60% coverage = fail) my pipeline should return an error. However, this does not happen. The quality gate says that the analysis was a success and quality gate is 'OK'. In another project, I removed some tests to make coverage be &lt;60% and the quality gate passed once again, even though it was meant to fail.</p>
  <p>I had an error related to the analysis always returning 0% coverage before, but managed to fix it (with help from <a href="https://steinar.bang.priv.no/2020/03/30/how-to-get-test-coverage-back-in-sonarcloud-maven-builds/" rel="nofollow noreferrer">this</a> link). Found a lot of articles with the similar questions but with no answers on any of them. This <a href="https://stackoverflow.com/questions/23673245/fail-sonarqube-quality-gate-when-coverage-decreases">post</a> looks promising but I cannot find the suitable alternative to its suggestion.</p>
  <p>It is worth mentioning that the analysis stage is done in parallel with another stage (to save some time). The Quality Gate stage comes shortly afterwards.</p>
  <p>The relevant code I use to initialise the analysis for my project is (org.jacoco... bit is the solution to 0% coverage error I mentioned above):</p>
  <pre><code>sh &quot;mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify sonar:sonar -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN} -Dsonar.projectKey=${projectName} -Dsonar.projectName=${projectName} -Dsonar.sources=. -Dsonar.java.binaries=**/* -Dsonar.language=java -Dsonar.exclusions=$PROJECT_DIR/src/test/java/** -f ./$PROJECT_DIR/pom.xml&quot;
  </code></pre>
  <p>The full quality gate code (to clarify how my quality gate starts and finishes):</p>
  <pre><code> stage(&quot;Quality Gate&quot;) {
        steps {
          timeout(time: 15, unit: 'MINUTES') { // If analysis takes longer than indicated time, then build will be aborted
              withSonarQubeEnv('ResearchTech SonarQube'){
                  script{
  
                  // Workaround code, since we cannot have a global webhook
                      def reportFilePath = &quot;target/sonar/report-task.txt&quot;
                      def reportTaskFileExists = fileExists &quot;${reportFilePath}&quot;
  
                      if (reportTaskFileExists) {
                          def taskProps = readProperties file: &quot;${reportFilePath}&quot;
                          
                          def authString = &quot;${env.SONAR_AUTH_TOKEN}&quot;                 
                          def taskStatusResult    =
                              sh(script: &quot;curl -s -X GET -u ${authString} '${taskProps['ceTaskUrl']}'&quot;, returnStdout: true)
                              //echo &quot;taskStatusResult[${taskStatusResult}]&quot;
                          def taskStatus  = new groovy.json.JsonSlurper().parseText(taskStatusResult).task.status
                          echo &quot;taskStatus[${taskStatus}]&quot;
  
                          if (taskStatus == &quot;SUCCESS&quot;) {
                              echo &quot;Background tasks are completed&quot;
                          } else {
                              while (true) {
                                  sleep 10
                                  taskStatusResult    =
                                      sh(script: &quot;curl -s -X GET -u ${authString} '${taskProps['ceTaskUrl']}'&quot;, returnStdout: true)
                                      //echo &quot;taskStatusResult[${taskStatusResult}]&quot;
                                  taskStatus  = new groovy.json.JsonSlurper().parseText(taskStatusResult).task.status
                                  echo &quot;taskStatus[${taskStatus}]&quot;
                                  if (taskStatus != &quot;IN_PROGRESS&quot; &amp;&amp; taskStatus != &quot;PENDING&quot;) {
                                      break;
                                  }
                              }
                          }
                      } else {
                          error &quot;Haven't found report-task.txt.&quot;
                      }
  
                      def qg = waitForQualityGate() // Waiting for analysis to be completed
                      if(qg.status != 'OK'){ // If quality gate was not met, then present error
                          error &quot;Pipeline aborted due to quality gate failure: ${qg.status}&quot;
                      }
                  }
              }
          }
        }
      }
  </code></pre>