Adding analysis to your Azure pipeline for a JS, TS, Go, Python, PHP, etc. project
On this page
This page explains how to add the SonarQube Cloud analysis to your Azure build pipeline for projects that are not Maven, Gradle, .NET, or C family projects.
Before starting, read Azure Pipelines integration overview.
Once you have created your project in SonarQube Cloud, set up the project integration with your DevOps platform and with Azure Pipelines, you can add the SonarQube Cloud analysis to your Azure build pipeline.
To create your Azure build pipeline, you can use either YAML or the Azure Classic interface.
- The use of the Classic interface is not always possible (e.g. if your code is stored on GitHub).
- If you use YAML, SonarSource can provide you with YAML templates or code examples.
If you need to use a specific scanner version, see Using a specific version of SonarScanner for .NET or CLI.
Using YAML
Add the following SonarQube tasks to your YAML pipeline:
- Before your build task, add a Prepare Analysis Configuration task.
- After your build task, add a Run Code Analysis task.
- After the Run Code Analysis task, add a Publish Quality Gate Result task.
See the YAML file example below. See also our YAML pipeline templates. For information about the SonarQube task inputs, see SonarQube tasks for Azure Pipelines.
Make sure the SonarQube task version used in your YAML file is the correct one.
For example, in SonarCloudPrepare@3
, @3
should correspond to the version of the Azure DevOps extension for SonarQube Cloud you're using.
YAML file example
trigger:
- master # or the name of your main branch
- feature/*
steps:
# Checkout the repository
- checkout: self
# Disable shallow fetch
fetchDepth: 0
# Prepare Analysis Configuration task
- task: SonarCloudPrepare@3
inputs:
SonarCloud: '<YourSonarqubeServiceEndpoint>'
scannerMode: 'cli'
configMode: 'manual'
cliProjectKey: '<YourProjectKey>'
# Add your build task(s) here
# Run Code Analysis task
- task: SonarCloudAnalyze@3
inputs:
jdkversion: 'JAVA_HOME_17_X64'
# Publish Quality Gate Result task
- task: SonarCloudPublish@3
inputs:
pollingTimeoutSec: '300'
Using the Classic interface
In the procedure below, the manual configuration mode is used to define analysis parameters at the pipeline level. You may use the sonar-project.properties
file instead (or another specified configuration file). For more information, see Choosing the configuration mode.
Proceed as follows:
- In Azure DevOps' Classic interface editor, create or edit your build pipeline.
- Add a Prepare Analysis Configuration task before your build task:
- In SonarQube Cloud Service Endpoint, select the SonarQube service connection you created in Adding the SonarQube service connection to your AzDO project in Setting up the integration for your project.
- Under Choose a way to run the analysis, select Use Standalone SonarScanner CLI.
- Select the Manually provide configuration mode.
- In the Project key field, enter your project key.
- Add a new Run Code Analysis task after your build task.
- Add a new Publish quality gate Result on your build pipeline summary.
- Ensure that the pipeline runs automatically for all the branches you want:
- Under the Triggers tab of your pipeline, select Enable continuous integration and select all the branches for which you want SonarQube Cloud analysis to run automatically.
- Save your pipeline.
Related pages
- Enabling the pull request and branch analysis
- Adding analysis to your Azure pipeline for a Gradle or Maven project
- Adding analysis to your Azure pipeline for a .NET project
- Adding analysis to your Azure pipeline for a C family project
- Adding analysis to your Azure pipeline for a monorepo
- SonarQube tasks for Azure Pipelines
Was this page helpful?