Jenkins and sonar integration with groovy script (pipeline - withSonarQubeEnv)

I want to do the jenkins and sonar integration using groovy script.

I already installed all the necessary plugins in Jenkins (SonarQube Scanner, Sonar Quality Gates Plugin, SonarQube Scanner,
Quality Gates Plugin). I created the webhook in Sonar (http: // myserver-sonarqube: 8080 / sonarqube-webhook) and the same is receiving information payload
of jenkins when I run package mvn.

Follow my code:

However when I run the Job the result is the following:

java.lang.IllegalStateException: Unable to guess SonarQube task id and/or SQ server details. Please use the ‘withSonarQubeEnv’ wrapper to run your analysis.
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:159)

I already configured the Sonar and Quality Gate in jenkins and still the error persists. Does anyone know how I can solve it?

Thank you!

Hi,

The stage setup looks okay. My eye is caught, however by this -f my-package/pom.xml. It looks like you’re analyzing a module from the project directory(…?). And if so, could you check my-package/target to see if that’s where analysis is storing its files?

Ann

Hi G Ann Campbell,

Thanks a lot for the help.

I’ve changed what you said (mvn clean install -U -DskipTests -f /var/lib/jenkins/scripts/test_groovy/my_source/ sonar: sonar), but the error is the same.

I deleted all the Sonar / Jenkins webhook settings and did it all over again. The return of the error has changed. Every time I run Job on Jenkins he always has the same answer: ERROR, but not all code has been re-published in Quality Gate.

This is the feedback I’m getting now:

The task “AWXu3i7Z8SfODCgvm3zQ” is always the same regardless of the source code it analyzes. Is this normal?

My current code:

Hi,

Could you please share the version of the SonarQube Jenkins plugin you are using, since we changed the behavior to find the task id in the previous releases.

Thanks