I am using a azure devops pipeline (api.UserManagement-CI) to run sonar cloud analysis. I have a code repo (api.UserManagement) which I am referring for analysis. I am using template for same. Sonar cloud should analysis for code repo (api.UserManagement). But it is actually analyzing devops pipeline (api.UserManagement-CI).
api.UserManagement-CI Code
resources:
repositories:
- repository: templates
name: tool.PipelineTemplates
type: git
ref: sonar-coverage- repository: apiusermanagement
name: api.UserManagement
type: git
ref: sonar-coveragestages:
- stage: build
jobs:
- template: dotnet-core/dotnet-core-build.yml@templates
parameters:
buildConfiguration: ‘${{ variables.buildConfiguration }}’
nugetFeed: ‘${{ variables.nugetFeed }}’
services:
- name: ‘UWA.UserManagement.API’
projectFile: ‘**/*.csproj’
repo: ‘apiusermanagement’
sonarQube: # include sonarQube object if using SonarQube
- runSonarQube: ‘false’
#sonarProjectKey: ‘396f872c49c107edb6601a1f2d3b2ae65cf08780’
#sonarProjectName: ‘EntryRequirementsAPI’
sonarCloud:- runSonarCloud: ‘true’
sonarCloudProjectKey: ‘UserManagementAPI’
sonarCloudProjectName: ‘UserManagementAPI’
sonarCloudProjectVersion: ‘$(VAL_uvgo_Version)’runDotNetCoreTests: ‘true’
coretest: 'true' vmImage: 'windows-2022'
tool.PipelineTemplates
- ${{ each sonar in s.sonarCloud }}:
- task: SonarCloudPrepare@2
displayName: ‘Run SonarCloud Analysis’
condition: and(succeeded(), eq(‘${{ sonar.runSonarCloud }}’, ‘true’))
inputs:
SonarCloud: ‘SonarCloudConnection’
organization: ‘uwa-dev’
scannerMode: ‘MSBuild’
projectKey: ${{ sonar.sonarCloudProjectKey }}
projectName: ${{ sonar.sonarCloudProjectName }}
projectVersion: ${{ sonar.sonarCloudProjectVersion }}I not pr branch then add branch name
${{ if and(eq(sonar.checkForQualityGate, true), ne(variables['Build.Reason'], 'PullRequest')) }}: extraProperties: | sonar.branch.name=${{ resources.repositories['apiusermanagement'].ref }} sonar.qualitygate.wait=true sonar.qualitygate.timeout=1800 sonar.sources=$(Build.SourcesDirectory)/api.UserManagement sonar.tests=$(Build.SourcesDirectory)/api.UserManagement/tests sonar.coverageReportPaths=$(Build.ArtifactStagingDirectory)/CoverageResults/Cobertura.xml sonar.testExecutionReportPaths=$(Build.ArtifactStagingDirectory)/CoverageResults/index.html