Why do I get a cache miss with ANALYSIS_MODE_INELIGIBLE in sonar-scanner on all the files?

When I run sonar-scanner in a PR (with sonar.pullrequest.* params) with the cache I get

Hit the cache for 7702 out of 7702

When I run sonar-scanner on the main branch (with sonar.branch.name) with the cache I get:

Hit the cache for 0 out of 7702
INFO: Miss the cache for 7702 out of 7702: ANALYSIS_MODE_INELIGIBLE [7702/7702]

Why is that? How can I use the cache while running the analysis on the main branch?

Hey there.

As noted in the template post – what version of SonarQube are you using?

Sorry about that. We are using version 5.0.1.3006

INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.8 Alpine (64-bit)
INFO: Linux 5.15.0-1039-aws amd64
INFO: SONAR_SCANNER_OPTS=-Xmx2048m
INFO: User cache: /opt/sonar-scanner/.sonar/cache

Close! That’s the scanner version, you can find the SonarQube version both in the scanner logs or in the footer of your SonarQube instance.

Hi Colin, actually we are sending the results to SonarCloud. I tried reading through the logs but couldn’t find the version of SonarQube there…

Okay! You filed this under the SonarQube category rather than SonarCloud, which is why I was confused. :slight_smile:

Here’s the deal – while the cache works with pull request analysis, it does not work yet with branch analysis.

It works with PR analysis because we only see the files belonging to the PR and the others are discarded. This is what we’re calling “incremental analysis” – and what the cache is designed for today.

For branch analysis this is different: an analysis of the main branch shows the analysis for the entire branch. We haven’t gotten to the point of being able to confidently merge existing analysis results and new analysis results and display that as a new analysis, which would be required for the main branch.

Thus, when you analyze a main branch, all files are ineligible to use the cache.

It’s on the list, but we prioritized PR analysis because developers typically have less time to wait for a PR analysis than for a main branch analysis.

Thanks, Colin, that’s a very exhaustive explanation. It helps :slight_smile:
I would even suggest to add it to the documentation, to help people understand what are the use cases of the cache.

Currently Sonar-scanner takes a very long time analysing our project (almost 8 minutes, which starts to be unbearable for the pipeline of our application). I was hoping the cache could help speeding up things, but now I understand this is not possible.

(and sorry for filing it under the wrong category, I was confused. I was actually looking for sonar-scanner and couldn’t find it, so I thought sonarqube was the right one :sweat_smile:)

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