No previous SonarQube analysis found on this pipeline execution. Please use the 'withSonarQubeEnv' wrapper to run your analysis

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 7.9.1 (on a remote server)
    Sonar maven plugin 3.7.0.1746 (in my pom.xml file)
    Jenkins 2.222.1 (local server)
    Maven 3.6.0

  • what are you trying to achieve
    Try to get sonar’ quality gate result

  • what have you tried so far to achieve this
    Here is below my pipeline. On my Sonar server, the server is said unreachable. When I try to connect to my jenkins/sonarqube-webhook/ I have first : This URL requires POST and when I try again with a post I have HTTP ERROR 400 Invalid JSON Payload.
    Yet, the quality gate result is quite clear :

    "serverUrl": "https://****/sonar",
    "taskId": "AXGHZCWeQLkOZHj6Wg_V",
    "status": "SUCCESS",
    "analysedAt": "2020-04-17T09:06:51+0000",  ...
    

```pipeline{

    agent {
        label "master"
    }

    tools {
        // Note: this should match with the tool name configured in your jenkins instance (JENKINS_URL/configureTools/)
        maven "Maven 3.6.0"
        jdk 'Java 1.8'
    }

    environment {
        // This can be nexus3 or nexus2
        NEXUS_VERSION = "nexus3"
        // This can be http or https
        NEXUS_PROTOCOL = "http"
        // Where your Nexus is running
        NEXUS_URL = "192.168.1.8:8081"
        // Repository where we will upload the artifact
        NEXUS_REPOSITORY = "repository-example"
        // Jenkins credential id to authenticate to Nexus OSS
        NEXUS_CREDENTIAL_ID = "nexus-credentials"
    }

    stages {

        stage ('Initialize') {
            steps {
                sh '''
                echo "PATH = ${PATH}"
                echo "M2_HOME = ${M2_HOME}"
                '''
            }
        }

        stage("mvn clean deploy") {
            steps {
                script {
                    // If you are using Windows then you should use "bat" step
                    // Since unit testing is out of the scope we skip them
                    sh "mvn -B clean deploy"
                }
            }
        }
        stage ("SonarQube check") {
            steps {
                script {
                    sh 'mvn -B -X sonar:sonar'

                    qualitygate = waitForQualityGate()
                    if (qualitygate.status != "OK") {
                        currentBuild.result = "UNSTABLE"
                    }
                }
            }
        }
     }
  }```

I have also tried to follow the documentation with this type of pipeline :

    ```stage ("SonarQube check") {
                steps {
                    withSonarQubeEnv('SonarTiss') {
                    sh '-B -X sonar:sonar'
                    }
                }
            }

            stage("Quality Gate") {
                steps{
                    timeout(time : 1, unit : 'HOURS'){
                        waitForQualityGate abortPipeline: true
                    }
                }
            }```

But then I have this error :  

```    Injection des variables d'environnement SonarQube en utilisant la configuration: SonarTiss
[Pipeline] {
[Pipeline] sh
+ -B -X sonar:sonar
/var/lib/jenkins/workspace/Pipe_Jeu_Alexis@tmp/durable-7968e6b1/script.sh: 1: /var/lib/jenkins/workspace/Pipe_Jeu_Alexis@tmp/durable-7968e6b1/script.sh: -B: not found
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Quality Gate)
Stage "Quality Gate" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE```

Hello Alexis,
from your post I understand you have fixed your issue with the analysis credentials for which you opened this earlier thread?
If indeed the case, do not hesitate to post a feedback there about how you fixed it.

Now about your quality gate status retrieval in your pipeline:

  • are you on the last SonarQube plugin version for Jenkins (2.11)?
  • did you set your Jenkins target URL with the final ‘/’ (I guess you have but let’s check all angles)
  • did you configure a secret in your Jenkins plugin, secret your pipeline would check for payload validity as described with the Configure a webhook secret section here.

Best regards
Sylvain

Hello Sylvain,

I just fixed my problem. This is how I have proceeded (by the way My plugin was indeed the 2.11 and the ‘/’ was on the jenkins URL) :

pipeline {

    agent {
        label "master"
    }

    tools {
        // Note: this should match with the tool name configured in your jenkins instance (JENKINS_URL/configureTools/)
        maven "Maven 3.6.0"
        jdk 'Java 1.8'
    }

    environment {
        // This can be nexus3 or nexus2
        NEXUS_VERSION = "nexus3"
        // This can be http or https
        NEXUS_PROTOCOL = "http"
        // Where your Nexus is running
        NEXUS_URL = "192.168.1.8:8081"
        // Repository where we will upload the artifact
        NEXUS_REPOSITORY = "repository-example"
        // Jenkins credential id to authenticate to Nexus OSS
        NEXUS_CREDENTIAL_ID = "nexus-credentials"
    }

    stages {

        stage ('Initialize') {
            steps {
                sh '''
                echo "PATH = ${PATH}"
                echo "M2_HOME = ${M2_HOME}"
                '''
            }
        }

        stage("build & sonar analysis ") {
        agent any
            steps {
                withSonarQubeEnv('SonarTiss'){
                    // If you are using Windows then you should use "bat" step
                    // Since unit testing is out of the scope we skip them
                    sh "mvn -B clean deploy sonar:sonar"
                }
            }
        }

        stage ("Quality Gate ") {
            steps {
                timeout(time: 1, unit: 'HOURS') {
                    waitForQualityGate abortPipeline: true
                }
            }
        }
    }
}


Thanks for sharing!