Gitlab MR Decoration without manually inputting project id

Relates to things like:

We’re currently using Sonarqube Developer’s Edition v9.9.
We have our Gitlab Integration hooked up and working. We’re able to send information to Sonarqube just fine, and our MR pipeline blockers all work based on Quality Gate status, etc.

I’m wondering if there is a way to send the Gitlab Project ID to Sonar such that we can get the MR decoration working in Gitlab automagically. Right now we have to go into each Project → General Settings → Devops → etc etc and put in the Project ID.

We also have MANY projects being added to our Sonar instance, so it isn’t exactly feasible to manually edit each project. We also have intentions of adding MANY more. The projects are being created dynamically through our Gitlab pipeline’s service token using the sonar.projectKey, sonar.projectName, etc parameters.

Searching the webs, some folks mention there’s a key like sonar.gitlab.project_id. I’ve tried implementing this key into my Gitlab_ci.yml file’s script and I do see in the console that it’s getting parsed correctly to the numeric project id, but it doesn’t get registered in the project within Sonar itself.

So is there a way to automagically get the MR Decoration in Gitlab working without having manual intervention on every project?

Thanks!

Hey there.

If you create your projects via the Project Onboarding UI (Create Project > Gitlab**), this information should be populated automatically.**

If your project are provisioned manually or during their first analysis – then yes, you have to go back and fill in this information to get PR decoration working.

We have a roadmap item concerning this, and we made some first steps with GitHub + GitHub Actions already.

If you have a lot of existing projects, you might benefit from using APIs like POST api/alm_settings/set_gitlab-binding to automate this.

Thanks for the response, Colin
Would you happen to know if the gitlab_binding command is available via the maven sonar plugin such that I can set it in a command? like -Dsonar.set_gitlab_binding=${CI_PROJECT_ID}, or is this strictly an API call that has to be made?

It’s not possible to set it via an analysis parameter.