Query availability in `api/issues/search` endpoint

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    • SonarQube - * Community Edition Version 9.3 (build 51899)
  • what are you trying to achieve
    • I want to query api/issues/search endpoint with optional parameters right after running SonarScanner
  • what have you tried so far to achieve this
    • I get a response from the query. I observed that sometimes (I could not determine any patterns) the query returns 0 smells.

Hello everyone. I am using SonarQube and SonarScanner to analyze code smells in certain files. My workflow is the following (by using a code snippet).

  • Make sure SonarQube is up and the analysis directory has sonar-project.properties file.
    • sonar-project.properties file:
  • Run SonarScanner.
  • (Right after SonarScanner finishes the execution, immediately) Query the results from the following endpoint: /api/issues/search?componentKeys=PROJECT_NAME:FILE_PATH&types=CODE_SMELL&statuses=OPEN

I receive the expected smell results from the above endpoint. However, sometimes smell results are just empty (empty list). I could not identify any root cause for this behavior. I do not have SonarScanner logs for the cases where I receive 0 code smells. I re-ran SonarScanner for such files and received non-zero code smell results. I could not reproduce the cases by manual run where I obtained 0 smell results.

So, is there any minimum time that I should wait before querying SonarQube to obtain code smell results per file? What could be the reason for obtaining 0 code smells (which is completely false)?


There are two important points here.

First, if you’re querying by specific files, it may be that they legitimately have 0 issues.

Second, if you’re querying immediately after analysis completes, it’s quite likely you’re not getting the results of that analysis.

Analysis actually happens in two parts. Most of the work is done in your build agent. There, the Scanner creates an analysis report, bundles it and sends it to the server to be processed. When the server receives this report, it’s queued, then processed in the order in which it was received. Analysis report processing consists of storing issues and file-level values, and also (I honestly don’t know which part comes first) of calculating and storing directory- and project-level measures.

So an immediate query isn’t going to get the values from the analysis you just ran.

The best way to time this is to have your Quality Gate status published back to your CI. (The docs should get you started) At that point, server-side processing is complete. Then you can run your query.


1 Like

Hi Ann,

Thank you a lot for your insights. I will consider a solution accordingly.

Kind Regards.

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