I’m trying to set up SonarCloud with our Azure DevOps pipelines. I was able to do it just fine if the pipeline involved checking out only one repository, but if more than 1 needs checking out, it throws an error. I’m encountering a similar issue as the one described in this article:
Sonar not working with multiple Azure DevOps projects - SonarCloud - Sonar Community (sonarsource.com)
I’m using a Microsoft hosted agent to analyze a C# repository using Azure DevOps YAML pipelines. Here’s the error I’m getting when running the analyzer:
2023-06-05T13:59:06.9804285Z ##[section]Starting: Run Code Analysis using SonarCloud
2023-06-05T13:59:06.9915599Z ==============================================================================
2023-06-05T13:59:06.9915732Z Task : Run Code Analysis
2023-06-05T13:59:06.9915800Z Description : Run scanner and upload the results to the SonarCloud server.
2023-06-05T13:59:06.9915911Z Version : 1.38.0
2023-06-05T13:59:06.9915967Z Author : sonarsource
2023-06-05T13:59:06.9916029Z Help : Version: 1.38.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
2023-06-05T13:59:06.9916284Z ==============================================================================
2023-06-05T13:59:07.2498576Z [command]D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.35.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
2023-06-05T13:59:07.2822477Z SonarScanner for MSBuild 5.13
2023-06-05T13:59:07.2823118Z Using the .NET Framework version of the Scanner for MSBuild
2023-06-05T13:59:07.3253068Z Post-processing started.
2023-06-05T13:59:07.4455236Z 13:59:07.436 13:59:07.436 WARNING: File 'D:\a\1\current\Xrm\Code\Plugins\***.cs' is not located under the base directory 'D:\a\1\s' and will not be analyzed.
2023-06-05T13:59:07.4459748Z 13:59:07.436 13:59:07.436 WARNING: File 'D:\a\1\current\Xrm\Code\Plugins\***.cs' is not located under the base directory 'D:\a\1\s' and will not be analyzed.
...
...
2023-06-05T13:59:08.0581191Z ##[error]13:59:08.045 No analysable projects were found. SonarCloud analysis will not be performed. Check the build summary report for details.
13:59:08.045 Post-processing failed. Exit code: 1
2023-06-05T13:59:08.0581988Z 13:59:08.045 No analysable projects were found. SonarCloud analysis will not be performed. Check the build summary report for details.
2023-06-05T13:59:08.0582369Z 13:59:08.045 Post-processing failed. Exit code: 1
2023-06-05T13:59:08.0582936Z 13:59:08.029 13:59:08.029 WARNING: File 'D:\a\1\current\Xrm\Code\Plugins\Model\OptionSets\***_statuscode.cs' is not located under the base directory 'D:\a\1\s' and will not be analyzed.
2023-06-05T13:59:08.0583692Z 13:59:08.029 13:59:08.029 WARNING: File 'D:\a\1\current\Xrm\Code\Plugins\Model\OptionSets\***.cs' is not located under the base directory 'D:\a\1\s' and will not be analyzed.
...
...
2023-06-05T13:59:08.0778611Z 13:59:08.045 Generation of the sonar-properties file failed. Unable to complete the analysis.
2023-06-05T13:59:08.0816844Z ##[error]The process 'D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.35.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 1
2023-06-05T13:59:08.0885326Z ##[section]Finishing: Run Code Analysis using SonarCloud
Based on my investigations, SonarScanner is picking up the wrong base directory (D:\a\1\s
), instead of D:\a\1\current
.
Here is scenario 1, of a pipeline that works:
jobs:
- job: build_plugin_assemblies
displayName: Build and Test Plugin Assemblies
variables:
solution: ${{ parameters.slnPattern }}
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- checkout: self
path: current
submodules: recursive
fetchDepth: 0
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
retryCountOnTaskFailure: 3
inputs:
restoreSolution: '$(Pipeline.Workspace)/current/$(solution)'
vstsFeed: '#{COMPANY_NAME}#-shared'
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: 'SonarCloud-ADO'
organization: '#{COMPANY_NAME}#-retail'
projectKey: '#{COMPANY_NAME}#-retail_$(Build.Repository.Name)'
projectName: $(Build.Repository.Name)
- task: VSBuild@1
displayName: Build plugin assemblies
inputs:
solution: '$(Pipeline.Workspace)/current/$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: SonarCloudAnalyze@1
displayName: 'Run Code Analysis using SonarCloud'
Here is scenario 2, of a pipeline that doesn’t work because I’m checking out the extra repo at the end:
jobs:
- job: build_plugin_assemblies
displayName: Build and Test Plugin Assemblies
variables:
solution: ${{ parameters.slnPattern }}
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- checkout: self
path: current
submodules: recursive
fetchDepth: 0
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
retryCountOnTaskFailure: 3
inputs:
restoreSolution: '$(Pipeline.Workspace)/current/$(solution)'
vstsFeed: '#{COMPANY_NAME}#-shared'
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: 'SonarCloud-ADO'
organization: '#{COMPANY_NAME}#-retail'
projectKey: '#{COMPANY_NAME}#-retail_$(Build.Repository.Name)'
projectName: $(Build.Repository.Name)
- task: VSBuild@1
displayName: Build plugin assemblies
inputs:
solution: '$(Pipeline.Workspace)/current/$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: SonarCloudAnalyze@1
displayName: 'Run Code Analysis using SonarCloud'
- checkout: utils
path: utils
fetchDepth: 1
Here is scenario 3, of a pipeline that still doesn’t work, even though I’m setting the project base dir in the SonarCloudPrepare
step:
jobs:
- job: build_plugin_assemblies
displayName: Build and Test Plugin Assemblies
variables:
solution: ${{ parameters.slnPattern }}
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- checkout: self
path: current
submodules: recursive
fetchDepth: 0
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
retryCountOnTaskFailure: 3
inputs:
restoreSolution: '$(Pipeline.Workspace)/current/$(solution)'
vstsFeed: '#{COMPANY_NAME}#-shared'
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: 'SonarCloud-ADO'
organization: '#{COMPANY_NAME}#-retail'
projectKey: '#{COMPANY_NAME}#-retail_$(Build.Repository.Name)'
projectName: $(Build.Repository.Name)
extraProperties: |
sonar.projectBaseDir=$(Pipeline.Workspace)/current
sonar.working.directory=$(Pipeline.Workspace)/current
- task: VSBuild@1
displayName: Build plugin assemblies
inputs:
solution: '$(Pipeline.Workspace)/current/$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: SonarCloudAnalyze@1
displayName: 'Run Code Analysis using SonarCloud'
- checkout: utils
path: utils
fetchDepth: 1
Both scenarios 2 & 3 are throwing the same error as described at the beginning of the thread.
Could you please offer some support so that I can achieve checking out multiple repositories within the same pipeline (scenarios 2 &3)?