I’m trying to configure organization-level default settings so that any new project automatically created in SonarCloud starts with the correct configuration.
We have a monorepo where projects/modules can be created dynamically by the scanner. Because of that, we would like to define defaults at the organization level rather than having to configure every new project individually after it has already been created.
Specifically, we want newly created projects to:
Use main as the default branch instead of master.
Use a 30-day New Code definition instead of previous_version.
I tried configuring these settings through the API at the organization level, but they appear to be unsupported.
- Steps to reproduce:
POST api/settings/setwithorganization=<org>andkey=sonar.projectCreation.mainBranchName,value=main- Same call with
key=sonar.leak.period.type,value=days - Same call with
key=sonar.leak.period,value=30 - All three return the “can’t be set at organization level” error
- As a result, every new project auto-created by the scanner is born with
masteras its default branch (so subsequentmainanalyses land on a non-default branch and the dashboard shows “not analyzed” until manually fixed) andprevious_versionas its New Code definition (which never resets, since our CI pipeline never setssonar.projectVersion)
- Potential workaround:
Currently fixing each new project manually after creation viaapi/project_branches/rename(tomain) andapi/settings/setscoped to the individualcomponent(for New Code = 30 days). This works per-project but requires a manual step (or a pre-scan provisioning call from CI) every time a new module is added to the monorepo. Requesting whether org-level defaults for these two settings are planned, since SonarQube Server supports them as global defaults today.