Unable to guess SonarQube task id and/or SQ server details. Please use the 'withSonarQubeEnv'

Hi!

Sonarqube: 8.9.0
Jenkins: 2.426.3
Plugins:

  • Sonar quality gates plugin: 1.3.1
  • Sonarqube scanner for jenkins: 2.17.2

Jenkins is installed in a specific server.
Sonar is installed in a docker image in another specific server.

I have a pipeline with 4 stages (build, test, sonar analysis and quality gate).

I get everything all right until 3 stage (I can read the statistics in the sonar server). But I get an error on the 4 stage when I’m trying to get the quality gate.

So, on the firts stage, I build a docker image to compile my java project. On the second, I run this image and execute the tests of my application. On the third, I execute the sonar analysis. On the fourth, I try to get the quality gate.

Follow a peace of code of third and four stages:

stage("Sonar Analysis") {
  steps{
    script{
      withSonarQubeEnv('Sonar') {
        sh "docker exec -w /tmp ${nameContainerTemp} mvn verify sonar:sonar - Dsonar.projectKey=NAME -Dsonar.host.url=URL -Dsonar.login=TOKEN"
      }
    }
  }
}

stage('Quality Gate') {
  steps {
    script {
      timeout(time:1, unit: 'HOURS') {
        def qg = waitForQualityGate()
        if (qg.status != 'OK') {
          error "Pipeline abortada devido a falha do Quality Gate: ${qg.status}"
        }
      }
    }
  }
}

I got this erro: Unable to guess SonarQube task id and/or SQ server details. Please use the ‘withSonarQubeEnv’ wrapper to run your analysis.

I believe that this error occur because the sonar analysis is executed inside the docker image. So, when a use the method waitForQualityGate(), it is not found.

How can I get the quality gate?

Thanks in advance!
Gillian Lopes

Hi,

Your version is past EOL. You should upgrade to either the latest version or the current LTS (long-term support version) at your earliest convenience. Your upgrade path is:

8.9.10 → 9.9.4 → 10.4 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after upgrade, please come back to us.

Hi Colin!

I did the upgrade.

Now I’m getting this error: “An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.10.0.2594:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0”.
This is the third stage in my pipeline (Sonar Analysis) that was functioning on Sonar version 8.9.

I read that Sonar 9.9 needs java 17 and I have projects in java 1.8 in my company.
It’s not possible to change the java version on these projects. I believe that this is the error. When I’m using sonar 9.9, do I need to have all my projects in or greater than java version 17? Am I right? Or is there another solution for my case?

Some extras informations:

This is the basis of my docker image (dockerimage): “From maven:3.5.2-jdk-8-alpine”

To build my project, I use this command on my dockerfile: “RUN mvn -Dmaven.test.skip=true -P $SPRING_PROFILES_ACTIVE package” (First stage of my pipeline)

To execute sonar analysis, I use this command on my pipeline:

withSonarQubeEnv('Sonar') {
  sh "docker exec -w /tmp ${nameContainerTemp} mvn verify sonar:sonar -Dsonar.projectKey=PortalTransparencia -Dsonar.host.url=http://sonar.cg.df.gov.br:9000 -Dsonar.login=433335c56b7eff3b618fdf83cb7fc16453dfe2c5"
}

(Third stage of my pipeline)

Am I doing something wrong?

Thanks a lot!

SonarQube v9.9 does require analyzing with Java 11 or Java 17 – although you can continue to build with Java 8 as long as the analysis occurs using Java 11. The [Scanner Environment](Scanner environment documentation should be useful here.