SonarQube - Code Issue or SonarQube Timeout in Jenkins

Must-share information (formatted with Markdown):

  • what are you trying to achieve:
    At the moment during waitforquality gate we get ERROR, because Sonarqube goes down.
    We need a way to understand whether error is because of a code issue or a SonarQube Timeout
  • what have you tried so far to achieve this
 def qg = steps.waitForQualityGate()
        if (qg.status == 'ERROR') {
            currentBuild.result = 'UNSTABLE'

However this way I cannot understand what was the reason.
I can put in try catch, but what exception should we be looking for?

Hello @alfador,

I am not quite sure of your problem. Is it that you can distinguish a quality gate timeout than a quality gate error ?

  • If the problem is a timeout, you should not have qg.status == 'ERROR' and:
    – You could do a special processing on the timeout, different from an ERROR QG.
    – You can control the max timeout you want in your pipeline. See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/
  • If you already a long enough timeout, and that you still timeout you should look at why SonarQube takes so long to process the Quality Gate on the server side. You may have a performance problem there
  • Finally I would like to mention that a QG status in ERROR is not a symptom of build unstability. It just mean that the code, as of today, does not pass the quality gate. This is normal, completely part of the normal lifecycle of a project. What would be abnormal is to release the code (or promote to another stage like QA or whatever) when the QG is ERROR.

If the above does not answer your question, please elaborate more on what is the problem, attach logs if needed etc…

Regards, Olivier

Problem is that this status check is only OK for when there is a problem with the code, but what if you run before that a sonar scanner command before quality gate and then it fails?
A very good example of what I mean is:
First we get:
17:39:37 [main] ERROR org.sonarsource.scanner.maven.SonarQubeMojo - SonarQube server [https://sonarqube.dhl.com] can not be reached
during sonar scanner. Sometimes Sonarqube fails, which then leads to
17:39:43 java.lang.IllegalStateException: Unable to guess SonarQube task id and/or SQ server details. Please use the ‘withSonarQubeEnv’ wrapper to run your analysis.

I need to get all the possible exceptions and filter with try catches.
In general we need to make our build unstable only if the CODE is giving error, not because of there is no such task or if the server gives timeout.
How to get the proper exception for a timeout for example? That would be helpful?

TL:DR I need the java exception list, so I can filter different java exception from sonar based on conditions