Start FreeLog in
SonarQube Cloud | Advanced setup | CI-based analysis | Azure Pipelines

Analyze your repository with Azure Pipelines

On this page

Once your project is created and initiated from the repository you selected, you can follow the tutorial to configure your analysis with Azure DevOps Pipelines.

We provide a set of YAML templates on GitHub to help get you started. The following SonarQube Cloud templates are available to make the configuration of your pipeline easier:

  • .NET Core
  • .NET Desktop
  • Generic analysis
  • Generic analysis using an existing properties file
  • Gradle
  • Maven

The example below shows how you could set up a yml file for a single project:

trigger:
- master
 
pool:
 vmImage: windows-latest
 
steps:
- task: VisualStudioTestPlatformInstaller@1
 inputs:
   packageFeedSelector: 'nugetOrg'
   versionSelector: 'latestPreRelease'
 
- task: UseDotNet@2
 inputs:
   packageType: 'sdk'
   version: '6.x'
   includePreviewVersions: true
 
- task: NuGetToolInstaller@1
 inputs:
   versionSpec: '5.9.0'
   checkLatest: true
 
- task: DotNetCoreCLI@2
 inputs:
   command: 'restore'
   projects: '**/*.sln'
   feedsToUse: 'select'
 
- task: SonarCloudPrepare@3
 inputs:
   SonarCloud: 'SonarCloud'
   organization: 'mySonarCloudOrganization'
   scannerMode: 'dotnet'
   projectKey: 'myRepo_myProject1'
 
- task: DotNetCoreCLI@2
 inputs:
   command: 'build'
   projects: 'myproject1/solution.sln'
   arguments: '/nr:false' // this flag is important to avoid DLL lock for the 2nd build/analysis

 - task: SonarCloudPublish@3
        displayName: 'Code Analysis - Publish QG'
        inputs:
          pollingTimeoutSec: '300'

Analyzing Monorepo Projects with Azure Pipelines: Pipeline Configuration

If you want to analyze a monorepo that contains more than one project, you need to ensure that you specify the paths to each project for analysis in your azure-pipelines.yml file.

A typical yml file for a monorepo analysis should look something like this: 

# Template pipeline that build 2 distinct .NET projects, living in 2 separate folders in the repo. We are analyzing them on SonarCloud, each targets a specific SonarCloud project.
 
 
trigger:
- master
 
pool:
 vmImage: windows-latest
 
steps:
- task: VisualStudioTestPlatformInstaller@1
 inputs:
   packageFeedSelector: 'nugetOrg'
   versionSelector: 'latestPreRelease'
 
- task: UseDotNet@2
 inputs:
   packageType: 'sdk'
   version: '6.x'
   includePreviewVersions: true
 
- task: NuGetToolInstaller@1
 inputs:
   versionSpec: '5.9.0'
   checkLatest: true
 
- task: DotNetCoreCLI@2
 inputs:
   command: 'restore'
   projects: '**/*.sln'
   feedsToUse: 'select'
 
- task: SonarCloudPrepare@3
 inputs:
   SonarCloud: 'SonarCloud'
   organization: 'mySonarCloudOrganization'
   scannerMode: 'dotnet'
   projectKey: 'myRepo_myProject1'
 
- task: DotNetCoreCLI@2
 inputs:
   command: 'build'
   projects: 'myproject1/solution.sln'
   arguments: '/nr:false' // this flag is important to avoid DLL lock for the 2nd build/analysis
 
- task: SonarCloudAnalyze@3
 
- task: SonarCloudPrepare@3
 inputs:
   SonarCloud: 'SonarCloud'
   organization: 'mySonarCloudOrganization'
   scannerMode: 'dotnet'
   projectKey: 'myRepo_myProject2'
 
- task: DotNetCoreCLI@2
 inputs:
   command: 'build'
   projects: 'myProject2/solution.sln'
   arguments: '/nr:false'
 
- task: SonarCloudAnalyze@3

References:


Was this page helpful?

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

Creative Commons License