Getting started with Bitbucket Cloud
If your code is on Bitbucket Cloud, go to sonarcloud.io and click
You will be taken to the Bitbucket login page. Sign in using your Bitbucket credentials.
Welcome to SonarCloud
Once you have successfully logged in, you will see the SonarCloud welcome screen.
Click on Import projects from Bitbucket.
Set up your organization
Connect your Bitbucket Cloud workspace to SonarCloud
When prompted, grant permission for the SonarCloud application to access your Bitbucket Cloud workspace.
You must be an administrator of the workspace that contains the repository you want to analyze. You will already be an administrator of your default workspace. For any other workspace, you have to add your Bitbucket account to a user group with the Administer workspace permission enabled.
Create your SonarCloud organization
SonarCloud is set up to mirror the way that code is organized in Bitbucket Cloud (and other repository providers):
- Each SonarCloud project corresponds one-to-one with a Bitbucket project, which resides in its own Git repository.
- Bitbucket projects are grouped into Bitbucket workspaces.
- Each SonarCloud organization corresponds one-to-one with a Bitbucket workspace.
In this step, you will create a SonarCloud organization that corresponds to your Bitbucket workspace.
SonarCloud will suggest a key for your SonarCloud organization. This is a name unique across all organizations within SonarCloud. You can accept the suggestion or change it manually. The interface will prevent you from changing it to an already existing key.
Choose a plan
Next, you will be asked to choose a SonarCloud subscription plan. If all the repositories to be analyzed are public on Bitbucket Cloud then you can choose the free plan. Your code and analysis results will be publicly accessible at sonarcloud.io.
If you want to analyze one or more private repositories then you need to select a paid plan. Even with the paid plan you still have a 14 day free trial period. Once the 14 days have elapsed, the cost is based on the number of lines of code analyzed.
A plan is always associated one-to-one with a SonarCloud organization and therefore with a single Bitbucket workspace. If you want to onboard multiple Bitbucket workspaces, you must sign up for a separate plan for each.
Once you have chosen a plan and clicked Create Organization, your SonarCloud organization will be created!
Set up your analysis
The next step is to import the projects (that is, individual Git repositories) that you want to analyze from your Bitbucket workspace into your newly created SonarCloud organization, creating a corresponding SonarCloud project for each.
SonarCloud will present a list of the repositories in your Bitbucket workspace. Select those that you want to import and analyze and click Set Up.
The selected projects will be imported.
With Bitbucket Cloud projects the actual analysis is performed in your build environment (cloud CI, local machine, etc.). This means you have to configure your build process to perform the analysis on each build and communicate the results up to SonarCloud.
We refer to this analysis method as CI-based analysis (though it may take place in a cloud CI or a manually configured build environment) to contrast it with automatic analysis which works by SonarCloud directly accessing your repository and performing the analysis itself. However, automatic analysis is currently available only for GitHub projects and only for a subset of languages. It is currently not available for Bitbucket Cloud projects.
SonarCloud will guide you through a tutorial on how to set up your build environment to perform analysis.
The first step is to select your build environment. SonarCloud will present this page:
If you have no particular preference and are setting up a new project on Bitbucket Cloud, we recommend using Bitbucket Pipelines as your CI.
Follow the tutorial to set up your analysis.