Automation of GitHub project setup in SonarCloud

Hi!

We’re using GitHub and Jenkins for our CI pipeline. We have a lot of Java and Scala components so we need to be able to add them with as little overhead as possible. We also use quality gates in our pipeline so that Jenkins builds fail when a quality gate is not met.

Currently, adding new components requires manual import of GitHub project from SonarCloud web UI. Is there any way to automate this? I saw somebody mention some API in this forum, but I cannot find anything relevant in the docs.

Alternatively, is there any other approach to getting SonarCloud quality gates enforced but without manually setting up every new project?

Thanks!

Hello @jgracindexcom
and thanks for reaching out.

Currently, adding new components requires manual import of GitHub project from SonarCloud web UI. Is there any way to automate this? I saw somebody mention some API in this forum, but I cannot find anything relevant in the docs.

SonarCloud WEB API is documented there: https://sonarcloud.io/web_api, you find the link just below documentation from the ‘?’ icon. If you have some scripts already run when you create a new component, you could definitely use the api/projects/create endpoint to create your new SC projects.
Unfortunately any project you create with this API will be unbound, not allowing you to benefit from PR decoration (among other things).

Alternatively, is there any other approach to getting SonarCloud quality gates enforced but without manually setting up every new project?
There is one actually, the first analysis of your project can be allowed to create the project if it does not exist, if your token stored with Jenkins is granted ‘Create Projects’ permission.

Again this would create an unbound project, and you have the risk to multiply the number of unwanted project creations.

Best regards
Sylvain

Thanks, Sylvain. I’ll check it out.