Unable to wait to quality gate -- Unable to guess SonarQube task id and/or SQ server details. Please use the 'withSonarQubeEnv' wrapper to run your analysis

Hello.

Software version:

  • SonarQube 8.9.2
  • SonarQube Scanner (Jenkins) 2.11
  • SonarQube Scanner (Maven) 3.9.0.2155 (latest)

I do know that the Jenkins plugin is out dated, but the situation at my company is that the Jenkins is running almost 24/7 with builds and usually won’t be restarted and has no internet access. So updating stuff is not that easy. I know this sucks but that is the situation I currently have to deal with.

My Jenkinsfile stages that run the scan and the quality gate call look like this:

stage('SonarQube check') {
    runWhenNoErrorOccurred() {
        withSonarQubeEnv(credentialsId: 'xxxxxxxxxxxxxxxxxxxxxxxx', installationName: 'SonarQube') {
            dir(env.WORKSPACE) {
                bat 'mvn -B -f proj\\pom.xml sonar:sonar'
            }
        }
    }
}

stage('Quality gate') {
    runWhenNoErrorOccurred() {
        timeout(time: 36, unit: 'HOURS') {
            def qualityGate = waitForQualityGate()
             if (qualityGate != 'OK') {
                echo "An error occurred during SonarQube checks!"
                errorOccurred = true
            }
        }
    }
}

It led to the error Unable to guess SonarQube task id and/or SQ server details. Please use the 'withSonarQubeEnv' wrapper to run your analysis..

I checked the logs further and found this: 15:18:30 WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
If I am not mistaken, this happened before the quality gate stage is reached.

Before that the Sonar scan process is clearly finished:

15:17:49 [INFO] Analysis report generated in 17778ms, dir size=116 MB
15:18:11 [INFO] Analysis report compressed in 23750ms, zip size=40 MB
15:18:12 [INFO] Analysis report uploaded in 950ms
15:18:12 [INFO] ANALYSIS SUCCESSFUL, you can browse http://sonar/dashboard?id=my.project%3Amain
15:18:12 [INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
15:18:12 [INFO] More about the report processing at http://sonar/api/ce/task?id=XXXXXXXXXXXXXXX
15:18:27 [INFO] Analysis total time: 1:17:55.242 s

Any ideas how to fix this? I guess it is probably the out dated Jenkins Sonar plugin. :confused:

Hi,

Welcome to the community!

Setting aside the version of your Jenkins plugin (yes, I understand you’ll get it updated when you can) I think I see the problem in your pipeline:

Does a SonarQube configuration named “SonarQube” exist at the global level? Because the argument should be the name of the globally-defined SonarQube instance to use. Since you’re getting an error of “Unable to guess… server details” my assumption is that you do not have an instance configured in the Jenkins Global config named “SonarQube”.

Assuming I’m correct, that’s why it’s telling you “use the withSonarQubeEnv wrapper” as though you’re not doing that when clearly you are.

 
HTH,
Ann

Hi Ann,

thanks for your reply. It is configured in JENKINS_URL/configure, so that should be global. The scanner so far works in the old pipelines.

But we have 2 instances. Perhaps I did a mistake and took the wrong one. I’ll exchange it and test it.

Best regards,
green

Okay, I checked the old Jenkins job:

It does not use any credentials. So I changed the pipeline a bit:

stage('SonarQube check') {
    runWhenNoErrorOccurred() {
        withSonarQubeEnv(installationName: 'SonarQube') {
            dir(env.WORKSPACE) {
                bat 'mvn -B -f proj\\pom.xml sonar:sonar'
            }
        }
    }
}

Of course, the name is correct, I just had to remove some naming stuff. This pipeline call was generated.

Any other ideas?

Edit: I recreated everything in a VM with the same Jenkins and SonarQube version and it works there for some reason. The difference is the token that I use there. But running the scan works fine, only the QualityGate fails.
One thing that caught my eye is this: WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?

Edit2: Interestingly when I call the analysis results in my browser I get {"errors":[{"msg":"Insufficient privileges"}]}
Perhaps the rights are insufficient?

Hi,

It’s been a long time since I was hands-on with Jenkins, but going by the documentation your configuration isn’t correct. I.e. yours

withSonarQubeEnv(installationName: ‘SonarQube’) {

vs docs

withSonarQubeEnv(‘My SonarQube Server’) {

 
Ann

That is how it is. The code above was hand written, in order not to copy and corporate related stuff I am not able to paste here… Sorry.

So far I have tried other ways. I tried to set the Auth Token via -Dsonar.login on the call of the Sonar-Maven-Plugin. And now I just started a new try settings the credentials via Jenkins and using my new token.

Edit: I now ran it again but this time with:

def qualityGate = waitForQualityGate(webhookSecretId: 'SONAR')

But the result is the same.

I also tested it in a virtual machine. It works there. So my guess is that there are some issues with the security settings or some settings in Jenkins?

Hi,

I would stick to the format demonstrated in the docs: withSonarQubeEnv('nameGivenInstanceInGlobalConfig'). And make sure the credentials are specified in that config. You run the analysis inside that block and then when you subsequently call waitForQualityGate (with no args!) it makes all the relevant information from the analysis (e.g. instance URL and credentials) available to that second task.

 
Ann

I think I have found the issue. It was the directory… I changed the working directory and always got the warning WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
I switched into the maven project folder and now it works. I tried to set the parameter manually but that did not work.

dir(env.WORKSPACE) {
    bat 'mvn -B -f proj\\pom.xml sonar:sonar'
}

As you can see I switch into the WORKSPACE directory but the Maven command rund inside the “proj” folder. The report-task.txt is generated in proj\target\… not in WORKSPACE.

Thank you so far for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.