How to create SonarQube Projects from Bitbucket repos automatically

SonarQube 7.7 and Bitbucket server 6.2.7
How can I auto create a SonarQube project for each Bibucket Repo? I have followed the directions to configure SonarQube to authenticate with Bitbucket but I am unclear how to avoid manually creating a project for each Repo in SonarQube.

Hi @Rob_Duncan,

If you want to automate the creation of projects, you can use the web API projects/create.
You can see more information from the Web API doc.


Hi @Rob_Duncan,

Also interesting to note that SQ developer starting from 8.2 allows creating a project from BitBucketServer repositories either from the UI, or from a script using the endpoint api/alm_integrations/import_bitbucketserver_project. That way the project will be all configured to decorate PRs.

You might be interested to upgrade to the latest version as well.


1 Like

Hi @aurelie,

I have upgraded to 8.2 and have created a SonarQube project using projects/create but I need them to be linked to Bitbucket so they will provide decorative PR’s.

When I try api/alm_settings/list I can see the response includes "key": "Bitbucket Server", "alm": "bitbucket".

So I have tried api/alm_integrations/import_bitbucketserver_project and I get "msg": "ALM Setting 'Bitbucket Server' not found".

When I change almSetting to ‘bitbucket’ I get "msg": "personal access token for 'bitbucket' is missing"

I thought it was to do with the Bitbucket Personal Token so I tried adding even after deleting the Bitbucket Server ALM Integrations and re-adding them with a Personal Access token twice. The Bitbucket personal token as admin access to project and repo level.

Is there something I am missing?

@aurelie, I found by accident that the PAT in the SonarQube admin is not the same as the API uses. I used the api/alm_integrations/set_pat to set the pat and it worked. Now I just need to figure out how to get Bitbucket to send to SonarQube now I can setup projects linked to Bitbucket with the API.

Hi @Rob_Duncan,

Thanks for your return.

I’m not sure to understand your sentence:

edit: I think this refer to this thread


Correct @aurelie. The two are related but I felt they were separate topics so had the two threads.