Analyze Your Repository With Azure Pipelines

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.

The following SonarCloud 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@1
 inputs:
   SonarCloud: 'SonarCloud'
   organization: 'mySonarCloudOrganization'
   scannerMode: 'MSBuild'
   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
 

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@1
 inputs:
   SonarCloud: 'SonarCloud'
   organization: 'mySonarCloudOrganization'
   scannerMode: 'MSBuild'
   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@1
 
- task: SonarCloudPrepare@1
 inputs:
   SonarCloud: 'SonarCloud'
   organization: 'mySonarCloudOrganization'
   scannerMode: 'MSBuild'
   projectKey: 'myRepo_myProject2'
 
- task: DotNetCoreCLI@2
 inputs:
   command: 'build'
   projects: 'myProject2/solution.sln'
   arguments: '/nr:false'
 
- task: SonarCloudAnalyze@1



References:


© 2008-2022, SonarCloud by SonarSource SA. All rights reserved.