Sonar-scanner not finding cached files with gitlab

We have a gitlab CI with the following basic config for sonarqube:

Run Sonarqube:
  stage: Sonar
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" 
    GIT_STRATEGY: fetch
    GIT_DEPTH: "0"
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - sonar-scanner
  allow_failure: true

Scanning seems to work fine but for the cache, it won’t find any hits:

Restoring cache
00:05
Checking cache for Run Sonarqube-non_protected...
Downloading cache.zip from https://<s3-bucket> 
Successfully extracted cache
INFO: The Python analyzer was able to leverage cached data from previous analyses for 0 out of 298 files. These files were not parsed.

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

I’m not sure why it doesn’t have any hits, the cache extraction/location is the same (/.sonar/cache)

Any help is greatly appreciated!

Hey there.

This cache that the scanner speaks about is server-side, not the cache that contains plugins.

What version of SonarQube are you using? This information is requested ink the template post.

Hey Colin,

Thanks fore replying!

SonarQube version: Enterprise Edition Version 9.9
SonarScanner 4.8.0.2856

Forgive me, Its been a couple of years since I did this at another job. I thought the .sonar/cache directory was where it would cache previously analyzed file data to speed up the process for future scans of the same builds, but .sonar/cache is for the plugins of the scanner, is that correct?

So, after reading some other posts, I see where my confusion was here, for anybody coming across this:

  1. For language analyzers, it seems that caching locally c/c++ is available, but i don’t see that for python/javascript/etc.

  2. Next, that only Pull Requests/Merge Request analysis will cache hits from the server (thank you Colin). We were doing pipelines only on merges, but will probably change that to be MR’s to make use of the server side caching.

Cheers!

Correct.

Yes, however (I believe?) the local caching is deprecated in favor of the server-side caching.

I think that’s a great idea, so you can catch the issues before you merge them. That would be our recommended approach.

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