No caching for branch

When running sonarscanner on our PRs, it always uses a full analysis instead of incremental.

Output from log:

12:49:51.073 Downloading cache. Project key: xxx, branch: master.
12:49:51.093 Downloading from https://xxx/api/analysis_cache/get?project=xxx&branch=master failed. Http status code is NotFound.
12:49:51.094 Cache data is empty. A full analysis will be performed.

The called api returns an error message: “No cache for given branch or pull request”.

This happens for all my projects.

How can I enable caching? How can I see caching status of my projects?

We’re using SonarQube 10.5.1.

Hey there.

Has your target branch (master) been analyzed recently (in the last week?)

Yes, master branch has been analyzed 4 weeks ago

Well, that was 4 weeks ago!

As documented:

About inactive projects

Projects that are not analyzed for seven consecutive days are considered inactive, and SonarQube automatically deletes their cached data to free space in the database. See Branch analysis for more information on inactive branches and cached data.

I would suggest reanalyzing your main branch, and then see if the cache kicks in for your PRs.

2 Likes

Thanks for this documentation hint.
Is there an option to change the “7 Days” setting per project?

There is not. :confused:

1 Like

Ok, thanks anyway. You helped me to understand my issue. :+1:

Is there a way to change the caching target for a PR analysis? I’d prefer it if the analysis was against a cache of the PR branch rather than our main branch.

Hey, @clay.brooks!

It’s not possible to change the caching target.

I believe our thinking is that the cache of the target branch will have all the changes (including other changes not merged into the PR branch), and most of the time the goal of the PR build is not to build the PR branch, but the target branch with the PR changes.

Does that make sense?