Creating and importing projects
Overview
There are several ways to create a project in SonarQube Server:
- Import from DevOps Platforms: If your project is bound to a DevOps platform and you want to benefit from the integration features out of the box.
- Local project: For a project not linked to a DevOps platform, you can create your SonarQube project manually.
- Automate through the API: Both methods mentioned above can be automated using the Web API.
- First scan: If none of the above is relevant, you can create a project by scanning it for the first time.
All the above methods require the Create Projects permission.
Choosing a method for project creation
When a project is created in SonarQube Server through a first scan, the default configuration applies: default quality profile for each language, default quality gate, default visibility, a permissions template is applied if applicable, etc.
While this is handy, this method is not always desirable as it doesn’t allow a proper configuration upfront. If you want to configure your project before you run a first analysis, use one of the following options:
- Import from DevOps Platforms: If your project is hosted on GitHub, GitLab, Azure DevOps, or BitBucket.
- Local project: If your project is not hosted on a DevOps platform (in rare cases).
Importing a DevOps platform repository
Once the global-level integration with your DevOps platform is complete, you can create your SonarQube Server project by importing your DevOps platform repository. The so-created SonarQube Server project is “bound” to its Azure DevOps repository. With a bound project, you benefit from integration features, such as pull request decoration, code scanning alerts, permission synchronization, etc.
To import your repository, you need the Create Projects permission in SonarQube Server and the corresponding access rights on the repository.
To import a DevOps platform repository into SonarQube Server:
- In the top navigation bar of SonarQube Server, select the Projects tab.
- In the top right corner, select the Create Project > From <DevOps Platform> button.
- If your instance has multiple DevOps platform Integrations, select the configuration from which you want to import your project.
- Select the repository to be imported.
Starting in Enterprise Edition, you can import a monorepo. See Managing the projects of a monorepo.
Creating your SonarQube Server project manually (local project)
You need the Create Projects permission in SonarQube Server.
Proceed as follows:
- In the top navigation bar of SonarQube Server, select the Projects tab.
- In the top right corner, select the Create Project > Local Project button.
Automating project creation and import
When you have a large project base, it can be interesting to automate project creation and import using the Web API. If you're getting started with Web API, check out the Web API page.
Automate local project creation
Only using the Web API /api/projects/create
is enough to create a local project. A name and a project key are the only necessary parameters.
Automate the import of projects hosted on a DevOps platform
To provision a project from a DevOps platform, SonarQube Server needs to communicate with the said platform using a personal access token.
This is done in two steps. First, get the personal access token using the POST api/alm_integrations/set_pat
endpoint, then use the POST api/alm_integrations/import_<yourdevopsplatform>_project
to set up the automation.
- You'll first need to use the
POST api/alm_integrations/set_pat
endpoint to provide this token. Specify the following parameters:pat
: The personal access token itself.almSetting
: Optional. The DevOps Platform configuration name that you target. This can be hardcoded in your automation, or you can useGET api/alm_settings/list
to have the full list. If you have only one Devops platform configuration in your instance, you can skip this parameter.username
: Optional. Only for BitBucket Cloud, as the actual authentication token is the combination of the username and the personal access token.
2. Once you’ve provided the token, use the following import endpoint to set up the automation:
POST api/v2/dop-translation/bound-projects
The details of how to use these endpoints are documented in the Web API v2.0 documentation.
Was this page helpful?