Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-42954

Jenkins unable to operate SonarQube block

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • sonar-plugin
    • None
    • Jenkins 2.48
      Linux (CentOS)
      SonarQube 6.2

      (Based on: https://stackoverflow.com/questions/42909439/using-waitforqualitygate-in-a-jenkins-declarative-pipeline)

       It appears that stage like these are not possible?

      stage ("SonarQube analysis") {
           steps {
              script {
                 STAGE_NAME = "SonarQube analysis"
      
                 if (BRANCH_NAME == "develop") {
                    echo "In 'develop' branch, don't analyze."
                 }
                 else { // this is a PR build, run sonar analysis
                    withSonarQubeEnv("SonarGate") {
                       sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"   
                    }
                 }
              }
           }
        }
      
        stage ("SonarQube Gatekeeper") {
           steps {
              script {
                 STAGE_NAME = "SonarQube Gatekeeper"
      
                 if (BRANCH_NAME == "develop") {
                    echo "In 'develop' branch, skip."
                 }
                 else { // this is a PR build, fail on threshold spill
                    def qualitygate = waitForQualityGate()
                    if (qualitygate.status != "OK") {
                       error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
                    } 
                 }
              }
           }
        } 
      

      It fails with: "Please use the 'withSonarQubeEnv' wrapper to run your analysis.", but I am using it... Jenkins does not recognize it? full logs in the question link above.

            idanadar Idan Adar
            idanadar Idan Adar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: