This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

See latest version
Start Free
10.4 | Project administration | Creating and importing projects

Creating and importing projects

On this page

Overview

There are several ways to create a project in SonarQube:

  • Import from DevOps Platforms (Enterprise edition and above): If your project is bound to a DevOps platform and you want to benefit from the integration features out of the box (pull request decoration, code scanning alerts, permission synchronization, etc.), go to Create Project > Import from DevOps Platforms from the homepage.

    If you already have a DevOps platform Integration configured, you'll be able to directly use it. For example, by clicking Create Project > From GitHub.
  • Local project: For a project not linked to a DevOps platform, you can use Create > Local on the Projects page.
  • 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, which can be configured in Administration > Security > Global Permissions.

Choosing a method for project creation

When a project is created in SonarQube 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).

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 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.

  1. 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 use GET 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, you can use the following import endpoints to set up the automation:

  • GitHub: POST api/alm_integrations/import_github_project
  • GitLab: POST api/alm_integrations/import_gitlab_project
  • Azure DevOps: POST api/alm_integrations/import_azure_project
  • Bitbucket
    • Cloud: POST api/alm_integrations/import_bitbucketcloud_repo
    • Server: POST api/alm_integrations/import_bitbucketserver_project

The details of how to use these endpoints are documented in the Web API documentation.



Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License