0
votes

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?

1

1 Answers

2
votes

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, i.e. proxy or firewall to be able to access Jenkins from Sonarqube - it depends on your network.