Branches to keep when inactive feature is very consistent

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension) 9.9.6 Community edition
  • how is SonarQube deployed: zip, Docker, Helm → Helm
  • what are you trying to achieve: Trying to activate " Branches to keep when inactive" housekeeping rule for other branches like main and release-*
  • what have you tried so far to achieve this: Activated this from housekeeping rules section on sonarqube.

The issue that we are facing is, that the rule is very inconsistent sometimes it works and sometimes it does not work. Can you please suggest if we need to make some additional changes.

Hey there.

You’ll need to give some examples of when you expected it to work and when it didn’t, such as specific branch names. It’s possible they just don’t match the “Branches to keep when inactive” pattern you’ve configured!

Hello Colin ,

Sorry for the late response. In the below screenshot, if you see, the master branch was already there and we want to protect main branch from getting deleted. If we add another branch “main” to make it protected then the sonar is not very certain to protect this branch or even the release/* branches. On some occasions the “keep when inactive” option gets checked after saving those branches. If we try the same rule on another sonar server(staging) it may or may not work. We execute fresh pipelines to apply the rules every time we make any change.

Based on your screenshot, everything appears to be working well. I would suggest you keep two things in mind:

  • This protection (based on the branch pattern)only applies when the branch is created, and adding patterns to Branches to keep when inactive will not retroactively apply to existing branches.
  • Users can manually adjust the “keep when inactive” button (by… clicking on it). If branches appear to magically be changing, you might want to check your access.log file for uses of POST api/project_branches/set_automatic_deletion_protection.

thanks for your response again Colin. Yes the screenshot which I shared is working one, but yes to confirm it just worked once. When we reset and try again then it’s like below(screenshot and never gets enabled). Another point is, we have tried this rule on a new branch “develop” also but we had the same result.

What do you mean by “reset”?

We first tested this in dev environment, for which we added “main” branch in “branches to keep when inactive” as below:

We ran the sonar step for a project and found that the main branch had “keep when inactive option” checked as below by which we are assuming that the main branch is now safe and won’t be deleted even after applying when the purging happens for inactive branches.

Now, we tried the same steps in another sonar environment “staging” and found that the “Keep when inactive” option was unchecked even after running the sonar for a project in staging for main branch which had exactly the same configuration as dev.

So, we came back again to dev and added another branch “develop” under “Branches to keep when inactive” as below:-

However, after running a sonar for a project on develop branch we still don’t see the check for “Keep when inactive” on develop branch. We also removed main from the list and added it back and ran the pipeline for main again for another project but found this function is very inconsistent and works occasionally.

I will summarize the issue to make it more simple. If we add a new branch/pattern under “Branches to keep when inactive” there is no surety that this branch will be protected from deletion as “Keep when inactive” checkbox may or may not get checked. This is true for a new branch as well in our case.

Another point is, we do not want to do this on the project level as there are multiple user projects. We aim to apply this rule globally for all projects from housekeeping rules. Please suggest if this is possible.

Hello Colin,

Could you please suggest if this can be fixed or if you need any more details ?