Jenkins pipeline withSonarQubeEnv generates sonar widget icon even when analysis fails to run

Is the withSonarQubeEnv command supposed to generate a sonar icon on a jenkins build even if sonar analysis fails?

I’m not sure if this expected behavior or not but I’m getting complaints from my users about this misleading them on the success of the sonar analysis,

When sonar analysis fails the sonar icon is displayed. (Screenshot attached). I would have expected the icon not to appear if analysis didn’t execute successfully.

using jenkins scripted pipeline syntax I have something like this:

withSonarQubeEnv(sonarServer) {
       returnCode = sh(returnStatus: true, script: "${sonarHome}/bin/sonar-scanner -foo" // foo forces a return 1
}

Sonar Server 7.7 (7.9 upgrade in the works)
Jenkins Sonar Scanner plugin version 2.11
sonarscanner version 4.0.0

For comparison, I don’t believe I get the artifactory icon (next to the sonar icon in the screenshot) if the build fails to complete artifact upload. To be fair I haven’t tested forcing a failure there but that’s how I thought it worked.

Hoping maybe somone from sonarqube could weigh in on this. Thanks

Hi @dg1,

I’m not sure I understand. Are you saying that the analysis fails (meaning, the scanner gives you an error, and cannot push the analysis to SonarQube), or do you mean that the analysis completes, the result is pushed to SonarQube, but SonarQube is failing? And if the latter, what is the failure: can’t SonarQube process the analysis report (i.e.: you have an error in your Background Tasks)? Or is the Quality Gate red?

It’s the former case. The scanner gives you an error and fails on the client side…any case where the return code would be 1. In my example above I passed an invalid parameter called “foo”, but the same thing would happen if my server url wasn’t valid.

@Wouter_Admiraal does that help?

Hi @dg1,

I was checking internally with my colleagues, because I cannot reproduce the error. Meaning, I don’t get the badge in case it fails. Are you using a scripted or a declarative pipeline?

Im using scripted pipelines. Are you at newer versions of things than the ones I have listed above? Maybe something was fixed?

What version of Jenkins are you using? Because I’m on the same Sonar plugin, and also using scripted pipelines. And the version of SonarQube should not make a difference in this case.