# Configuring project for Azure Pipelines

## Adding SonarQube service connection to Azure Pipelines (SonarQube endpoint) <a href="#adding-sonarqube-service-connection" id="adding-sonarqube-service-connection"></a>

Service connections are authenticated connections between Azure Pipelines and external or remote services. You must declare your SonarQube Cloud as a service connection in your Azure DevOps project.

Proceed as follows:

1. In SonarQube Cloud, create an authentication token that will be used by Azure DevOps to execute the analysis of your project in SonarQube Cloud. To do so, create a personal access token *and copy it* (Scoped Organization Tokens are not yet supported with Azure DevOps service connections). For more information about tokens, see [Managing Personal Access Tokens](/sonarqube-cloud/managing-your-account/managing-tokens.md).
2. In your Azure DevOps project, go to **Project Settings** > **Service connections**.
3. Select **New service connection** and then select **SonarQube Cloud** from the service connection list.

<div align="left"><figure><img src="/files/VajwMzc2jybfNsN8S6i0" alt="Search for &#x22;sonar&#x22; when adding a new service connection to your Azure DevOps pipeline." width="563"><figcaption></figcaption></figure></div>

4. Set the parameters:
   * In **Region (optional)** field: If you use the [SonarQube Cloud’s US instance](/sonarqube-cloud/getting-started/getting-started-in-us-region.md), select **US**. Otherwise, make sure **Global** is selected (default value).
   * In **SonarQube Cloud Token**, enter the token created in the first step.
   * In **Service Connection Name**, enter a memorable name (You will need this name when configuring your Azure build pipelines).

In the example below, the US instance is used.

<div align="left"><figure><img src="/spaces/KXW79zfYFiA8incTvwZK/files/chaX7L9vCuLBIs2s8fP1" alt="Enter the service connection parameters. By default, the EU instance (sonarcloud.io) is used. Select US if you use the US region."><figcaption></figcaption></figure></div>

5. Select **Verify** to verify the connection to the SonarQube Cloud's instance.
6. Select **Save** to save your connection.

## Enabling the pull request analysis in your build pipeline <a href="#enabling-pull-request-analysis" id="enabling-pull-request-analysis"></a>

The Azure DevOps extension running in your Azure pipeline can automatically detect branches or pull requests being built (you don't need to pass them as parameters to the scanner).

To enable the pull request analysis in your Azure pipeline of code stored on Azure DevOps, you must configure a pull request trigger on the target branch (main development branch) as explained on the [Configuring Azure DevOps project binding](/sonarqube-cloud/managing-your-projects/administering-your-projects/devops-platform-integration/azure-devops.md) page.

If your code is stored on GitHub or Bitbucket Cloud, open the expandable content below.

<details>

<summary>GitHub or Bitbucket Cloud</summary>

To configure a pull request trigger in your Azure build pipeline for code stored on GitHub or Bitbucket Cloud:

1. Select **Edit** to modify your build pipeline.
2. Go to the **Triggers** tab.
3. Select the correct repository under **Pull request validation**.
4. Select **Enable pull request validation**.
5. Set up the branch filters: Note that this is the **target** branch of the pull request. See the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops\&tabs=yaml#pr-triggers) for more details.
6. Select **Save** to update your pipeline.

</details>

## Related pages

* [Azure DevOps Extension](/sonarqube-cloud/analyzing-source-code/scanners/sonarcloud-extension-for-azure-devops.md)
* [Azure Pipelines integration overview](/sonarqube-cloud/analyzing-source-code/ci-based-analysis/azure-pipelines/azure-pipelines-integration-overview.md)
* [Adding analysis to build pipeline](/sonarqube-cloud/analyzing-source-code/ci-based-analysis/azure-pipelines/adding-analysis-to-build-pipeline.md)
* [Checking quality gate in release pipeline](/sonarqube-cloud/analyzing-source-code/ci-based-analysis/azure-pipelines/quality-gate-status-in-release-pipeline.md)
* [List of SonarQube tasks](/sonarqube-cloud/analyzing-source-code/ci-based-analysis/azure-pipelines/sonarqube-tasks.md)
* [Getting started in the US region](/sonarqube-cloud/getting-started/getting-started-in-us-region.md)

## Related online courses

* <i class="fa-desktop">:desktop:</i> [Configuring code analysis for SonarQube Cloud with Azure Pipelines](https://www.sonarsource.com/learn/course/sonarqube-cloud/d77cd975-f3c7-4ee9-bda5-9e25447d1c9b/configuring-code-analysis-for-sonarqube-cloud-with-azure-pipelines)
* <i class="fa-desktop">:desktop:</i> [Configuring code analysis for SonarQube Cloud with Azure Pipelines and GitHub repositories](https://www.sonarsource.com/learn/course/sonarqube-cloud/f90278ac-4ac4-4d2c-bb39-09c43ac296e9/configuring-code-analysis-for-sonarqube-cloud-with-azure-pipelines-and-github-repositories)
* <i class="fa-desktop">:desktop:</i> [Configuring pull request decoration for SonarQube Cloud using Azure DevOps](https://www.sonarsource.com/learn/course/sonarqube-cloud/4a81488c-81ec-4479-8f93-e7bda1a00351/configuring-pull-request-decoration-for-sonarqube-cloud-using-azure-devops)
* <i class="fa-desktop">:desktop:</i> [Configuring pull request decoration for SonarQube Cloud using Azure Pipelines and GitHub repositories](https://www.sonarsource.com/learn/course/sonarqube-cloud/b62c40a3-c875-40b4-ab65-47f49ecc85d1/configuring-pull-request-decoration-for-sonarqube-cloud-using-azure-pipelines-and-github-repositories)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-cloud/analyzing-source-code/ci-based-analysis/azure-pipelines/setting-up-project-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
