Projects get renamed after scanner runs on main branch

Hi!

We have used the sonarcloud API SonarQube Cloud to create projects programatically. We used the name key to set the project name and while the sonar analysis was running on a branch, it was all fine. However, after merging the sonar analysis PR (i.e. using https://www.npmjs.com/package/sonarqube-scanner to run the analysis on multiple projects in a monorepo) to main, all projects got renamed to the repo name.

Is there a requirement for every analysis to run with the project name set otherwise it gets overwritten? This is the documentation I used for building the scanner options, and I can’t see this behaviour mentioned in here -Parameters not settable in the UI | SonarQube Cloud | Sonar Documentation.

Thanks!

Hi,

Was this via the API when you were creating the project?

Projects can’t be renamed from a non-main branch

Take a look at what parameters you’re passing in analysis. sonar.projectName is actually optional, but when you pass it on a main-branch analysis, that’s the project’s (new?) name.

So run analysis one more time with the sonar.projectName value you want and then either delete the parameter from your configuration or leave it set to the correct name.

 
HTH,
Ann

Yes, exactly, using the key name.

We don’t pass sonar.projectName in the analysis. Is there a value applied to sonar.projectName by default if not specified? I can see when passing the verbose option, that sonar.projectName is set to the package name, but we don’t set it ourselves. Perhaps it’s set here - sonar-scanner-npm/src/properties.ts at 193e5c63319a3bf798831c3c14f515d6fc3056a8 · SonarSource/sonar-scanner-npm · GitHub?

Hi,

Nice find! Since a default value is being picked up automatically, you’ll need to override it. It’s probably easiest to add it to your analysis command line: -Dsonar.projectName=[the right one].

 
HTH,
Ann