Setting up project integration with Azure Pipelines
This page explains project-level settings required if you use Azure Pipelines for your project analysis.
Adding SonarQube service connection to Azure Pipelines (SonarQube endpoint)
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:
- In SonarQube Cloud, create an authentication token that will be used by Azure DevOps to execute the analysis of your project in SonarQube Server. To do so, create a token and copy it. For more information, see Managing your tokens.
- In your Azure DevOps project, go to Project Settings > Service connections.
- Select New service connection and then select SonarQube Cloud from the service connection list.
- Enter the SonarQube Cloud URL, the token created in the first step, and a memorable Service connection name (You will need this name when configuring your Azure build pipelines). Then, select Save to save your connection.

Enabling the pull request analysis in your build pipeline
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).
The procedures below explain how to configure a pull request trigger in your Azure build pipeline depending on your DevOps platform. You can also block the pull request merge if the quality gate fails.
Azure DevOps
To enable the pull request analysis in your Azure pipeline of code stored on Azure DevOps:
- Configure a pull request trigger on the target branch (main development branch). To do so, add a build validation policy on the branch (you cannot define pull request trigger in your pipeline):
- In the Branch policies page of your target branch, add a build validation policy that runs your build pipeline.
- Create an Azure DevOps Personal Access Token having a Code (read and write) scope.
- In SonarQube Cloud, set this token by navigating to Your Project > Administration > General Settings > Pull Requests > Integration with Azure DevOps Services.
- To prevent the merge of pull requests when the quality gate fails, proceed as follows (you can also watch this video for a quick overview of the procedure):
- After the first analysis on a pull request, go to the Branch policies page of your target branch.
- Under Require approval from additional services, select Add status policy.
- In the Status to check dropdown, select SonarQube Cloud/quality gate (you will not see the SonarQube Cloud quality gate until the analysis build has been run once).
- Then choose the option depending on your need:
- Optional: Users will be able to merge a pull request even if the quality gate fails.
- Required: Users will not be able to merge a pull request unless the quality gate passes.
- Select Save.
GitHub or Bitbucket Cloud
To configure a pull request trigger in your Azure build pipeline for code stored on GitHub or Bitbucket Cloud:
- Select Edit to modify your build pipeline.
- Go to the Triggers tab.
- Select the correct repository under Pull request validation.
- Select Enable pull request validation.
- Set up the branch filters: Note that this is the target branch of the pull request. See the Microsoft documentation for more details.
- Select Save to update your pipeline.
Was this page helpful?