简体   繁体   中英

How to receive quality gate status from SonarQube in Jenkins pipeline?

For the below pipeline script:

   stage('stage1'){

    withSonarQubeEnv(server){
            sh "${scannerHome}/bin/sonar-scanner"
        }
   }

stage1 launches Sonar scan and exit with success state.

stage2 waits for 30 minutes until sonar scan completes, jenkins is suppose to receive QualityGate status, as per below code.

   stage('stage2'){

        timeout(time: 40, unit: 'MINUTES') {
            def qGate = waitForQualityGate()
            if (qGate.status != 'OK') {
                error "Pipeline aborted due to quality gate failure: ${qGate.status}"
            }
        }
    }        

We have Sonar server and sonar scanner configured in Jenkins.

Is there additional configuration required to receive quality gate status?

To make it work you need:

  1. Sonarqube, use a recent version, LTS 6.7.x or 7.6
  2. the Sonarqube Jenkins plugin in version >= 2.6.1
  3. the Sonarqube scanner configured in Jenkins
  4. the Sonarqube host configured in Jenkins to make
    withSonarQubeEnv(nameofyourconfiguredSonarHost) work
  5. configure a webhook in Sonarqube server:
    goto https://yoursonarhost/admin/webhooks and use that URL
    https://yourjenkins/sonarqube-webhook/
    note the trailing '/' !

After that it should work as expected. In my experience a timeout of 10 mins is sufficient.
Maybe there are additional settings needed, ie proxy or firewall to be able to access Jenkins from Sonarqube - it depends on your network.

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