Using various features
Adding more SonarQube Server features to the analysis for your Azure build pipeline.
This section explains features you may use when adding SonarQube analysis to your Azure build pipeline:
Choosing the configuration mode (only in the Standalone SonarScanner CLI mode).
Choosing the configuration mode
In the CLI mode of the Azure DevOps extension for SonarQube Server, you may:
Either use the file configuration mode (default mode) which consists of setting analysis parameters in the
sonar-project.propertiesfile stored in the repository root (or another specified configuration file).Or use the manual configuration mode to define analysis parameters at the pipeline level.
If you use the manual configuration mode, the scanner still checks the sonar-project.properties file. Parameters set through the manual configuration mode have precedence over parameters set in the sonar-project.properties file.
Using the file configuration mode
The file configuration mode is the default mode of the Azure DevOps extension for SonarQube.
YAML pipeline for file configuration
Make sure the
configModeinput of theSonarQubePreparetask is set tofile.To use a different configuration file than
sonar-project.properties, add theconfigFiletask input to theSonarQubePreparetask, with the path to the configuration file as the value. The path can be absolute, or relative to the repository root.
Classic pipeline for file configuration
In the Prepare Analysis Configuration task:
Make sure the Store configuration with my source code mode is selected.
In Settings file, you can define a different configuration file than
sonar-project.properties. The path can be absolute, or relative to the repository root.
Using the manual configuration mode
To define analysis parameters at the pipeline level in Standalone SonarScanner CLI mode, proceed as described below.
YAML pipeline for manual configuration
Make sure the
configModetask input in theSonarQubePreparetask is set tomanual.Use the
extraPropertiestask input in theSonarQubePreparetask to define the analysis parameters: define a new sonar property by adding<propertyKey>=<propertyValue>on a new line.
Classic pipeline for manual configuration
In the Prepare Analysis Configuration task:
1. Select the Manually provide configuration mode and enter the required parameters.
2. In Advanced section > Additional properties, define a new sonar property by adding <propertyKey>=<propertyValue> on a new line.
Example: sonar.exclusions=**/*.bin
For information about the required settings in the SonarQubePrepare task for either configuration mode, see the Prepare Analysis Configuration task article.
Using a specific version of SonarScanner for .NET or CLI
The Azure DevOps extension for SonarQube Server embeds the latest compatible version of the SonarScanner for .NET and SonarScanner CLI. In very particular situations, you may want to use another scanner version. In such a case, you can configure the download of this specific version from the Sonar binaries site. In addition, you can use the Azure cache task(see below) in your pipeline to manage the caching of the SonarScanner.
The figure below shows the download process of a specific version of SonarScanner for .NET or SonarScanner CLI.
Set up the download in the Prepare Analysis Configuration task of your pipeline as described below.
SonarScanner for .NET
You must specify the full version number, such as 8.0.3.99785 (and not 8.0.3). All of the available version numbers can be found here.
YAML pipeline
Add the following input to the Prepare Analysis Configuration task:
dotnetScannerVersion: The SonarScanner for .NET version to be downloaded.
The code snippet below shows a task configuration example. For more information about the task inputs, see the SonarQube tasks for Azure Pipelines page.
- task: SonarQubePrepare@7
inputs:
SonarQube: '<YourSonarqubeServerEndpoint>'
scannerMode: 'dotnet'
dotnetScannerVersion: '8.0.3.99785'
projectKey: '<YourProjectKey>'Classic pipeline
In Scanner Version, enter the version to be downloaded.
SonarScanner CLI
You must specify the full version number, such as 6.0.0.4432 (and not 6.0.0). All of the available version numbers can be found here.
YAML pipeline
Add the following input to the Prepare Analysis Configuration task
cliScannerVersion: The SonarScanner CLI version to be downloaded.
The code snippet below shows a task configuration example. For more information about the task inputs, see the SonarQube tasks for Azure Pipelines page.
- task: SonarQubePrepare@7
inputs:
SonarQube: '<YourSonarqubeServerEndpoint>'
scannerMode: 'cli'
configMode: 'file'
configFile: 'my-config.properties'
cliScannerVersion: '6.0.0.4432'
cliProjectKey: '<YourProjectKey>'
cliSources: '.' Classic pipeline
In Scanner CLI Version, enter the version to be downloaded.

Using the cache feature
Azure DevOps allows pipeline caching to improve build performance by facilitating the download of dependencies between pipeline runs. Currently, you can only cache the SonarScanner (bootstrapper) that is downloaded when you need a specific version of SonarScanner for .NET or CLI.
Proceed as follows:
Add a cache task to your Azure build pipeline before SonarQube’s Prepare Analysis Configuration task. See the code snippet below according to the extension mode.
Disable comments in your pull requests
If you want to decorate your pull request with a quality gate status and are not interested to have SonarQube Server annotations in your PR, see the Disable pull request annotations article.
Related pages
Last updated
Was this helpful?

