简体   繁体   中英

What are all possible returned value in Jenkins plugin “Sonarqube scanner”

I have a Jenkins pipeline job which build my application, make a Sonar analysis and then is the quality gate passed I deploy in ou Nexus with mvn deploy .

The initial setup was to publish only in case of success (taken from the official doc ):

stage("Quality Gate"){
      timeout(time: 1, unit: 'HOURS') {
          def qg = waitForQualityGate()
          if (qg.status != 'OK') {
              error "Pipeline aborted due to quality gate failure: ${qg.status}"
          }
      }
    }

and now we want to change a bit the logic gate in Jenkins and we would like to publish in case there no error (but eg Warning is acceptable).

For that I changed the Jenkins satge to:

stage("Quality Gate"){
  timeout(time: 1, unit: 'HOURS') {
      def qg = waitForQualityGate()
      if (qg.status == 'Error') {
          error "Pipeline aborted due to quality gate failure: ${qg.status}"
      }
  }
}

stage('Deploy to Nexus') {
    sh "mvn deploy -DskipTests"
}

but now, it does not seems to work properly: my project is always pushed to Nexus even the Quality gate is in Error in SonarQube.

I have a possible workaround by changing the condition:

qg.status != 'OK' || qg.status != 'Warning' 

Anyone knows what is the exact value for the error status (and possibly other values)?

The documentation seems incomplete and there is no other way than guessing the correct return value.

For preventing such issue I suggest to test without exact case like this:

if ('error'.equalsIgnoreCase(qg.status) ) {
    error "Pipeline aborted due to quality gate failure: ${qg.status}"
} 

When using such condition my script is working fine, then it seems the value returned is in all capital case: 'ERROR'.

It's configurable via Webhooks in SonarQube Administration setup: https://docs.sonarqube.org/display/SONAR/Webhooks

So, the method returns whatever you have configured for all Gateway Rules for OK or failure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM