blueocean SonarQube Quality gate not working

311 views
Skip to first unread message

nup

unread,
Sep 8, 2017, 5:45:13 PM9/8/17
to Jenkins Users
Hi,

I have been trying to get SonarQube Quality gate to work with latest blueocean on Jenkins, but it does not seem to work.  I am a beginner with blueocean pipeline so any help in fixing this issue would be greatly appreciated.   Please, note the build works and sonarqube report is generated, but only failing at SonarQube Quality Gate status.  I thought this would work out of the box as blueocean now as an added Step to add SonarQube QG status.

I have tried all of the various different steps, but I still get following same error "Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis."

---------

pipeline {

  agent any

  stages {

    stage('Build') {

      steps {

        sh 'mvn install clean install -Dsonar.login=test -Dsonar.password=test -Dsonar.host.url=http://myserver sonar:sonar '

      }

    }

    stage('Quality Gate') {

      steps {

        sh 'echo "Sonar Analysis"'

        waitForQualityGate()

      }

    }


---------

    stage('Quality Gate') {

      steps {

        sh 'echo "Sonar Analysis"'

        withSonarQubeEnv('http://myserver') 

        waitForQualityGate()


      }

    }

-----------------

   stage('Quality Gate') {

      steps {

        sh 'echo "Sonar Analysis"'

        withSonarQubeEnv('http:myserver') 

        def qualitygate = waitForQualityGate()

        if (qualitygate.status != "OK") {

         error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"

      }

    }



------------


pipeline {

  agent any

      environment {

        withSonarQubeEnv = 'http://myserver/'

    }

  stages {

    stage('Build') {

steps {

sh 'mvn install  -Dsonar.login=test -Dsonar.password=test -Dsonar.host.url=http:myserver/ sonar:sonar '

  }

  }

    stage('Quality Gate') {

      steps {

        sh 'echo "Sonar Analysis"'

        waitForQualityGate()

    }

  }



------------

Daniel Beck

unread,
Sep 8, 2017, 7:12:03 PM9/8/17
to jenkins...@googlegroups.com

> On 8. Sep 2017, at 23:45, nup <npir...@gmail.com> wrote:
>
> I have tried all of the various different steps, but I still get following same error "Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis."
>

It's a wrapper, so try something like this:

}

Michal Propílek

unread,
Sep 18, 2017, 9:17:52 AM9/18/17
to Jenkins Users
Hi, you must using {} as wrapper. 

stage ('SonarQube Scan'){
            steps {
                withSonarQubeEnv('SonarQube') {
                    withMaven (
                        maven: 'maven 3.3.9',
                        mavenSettingsConfig: 'cc86690e-095d-4714-92b2-b61861241c7a'){
                        sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar '
                    }
                } // SonarQube taskId is automatically attached to the pipeline context
            }
        }
        stage ('Quality Gate') {
            steps {
                timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
                    script {
                        def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
                        if (qg.status != 'OK') {
                            error "Pipeline aborted due to quality gate failure: ${qg.status}"
                        }
                    }
                }
            }
        }




Dne pátek 8. září 2017 23:45:13 UTC+2 nup napsal(a):
Reply all
Reply to author
Forward
0 new messages