Setup branchesToKeepWhenInactive through sonar-project.properties

Hi,
i have troubles to setup housekeeping project settings in an sonarqube instance and i hope someone has an idea where i do something wrong.

I would like to setup the housekeeping setting “Branches to keep when inactive” for a lot of sonarqube projects, i can do this through the UI (Project → Project Settings → Housekeeping) but as we get constantly new projects i would like to setup this through e.g. the sonar-project.properties, which gets into all our projects through a template. I cannot change it for the whole instance as it is a shared instance and only “my” projects require this change.

The key for this settings seems to be sonar.dbcleaner.branchesToKeepWhenInactive, but whenever i add this to my properties file and push it to main and let an analysis run through, the setting does not get changed.
Other settings like sonar.projectName get applied without any problems in the same runs.

I tried to do it with simple ones like:
sonar.dbcleaner.branchesToKeepWhenInactive=main

also with other values like
sonar.dbcleaner.branchesToKeepWhenInactive=main, master, develop, release-.*

But the value i see in the ui never changed.

So.. Where am i doing something wrong? Is it not intended to setup this setting through the sonar-project.properties and only through the UI or maybe through the api?

I would be grateful if someone could point me in the right direction.

I tested this on a sonarqube server v2025.1 with SonarScanner CLI 7.1.0.4889.

Hi,

Welcome to the community!

While analysis-related values can be set - on a per analysis basis - as analysis parameters, this type of setting cannot. You’ll need to set this via the UI. Or perhaps on project creation through automated API calls.

The best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.

You may also find this guide helpful.

 
HTH,
Ann

1 Like

We faced the same task and thanks to the API hint we implemented a small CLI tool that redefines the sonar.dbcleaner.branchesToKeepWhenInactive setting on demand (not as part of a scan execution).

The only drawback I see is that it is not automatically applied when a new project is created by some scan. But this could be fixed by writing another tool which creates a project upfront and then immediately applies all custom settings that we need.