@jdinardo I’ve got it working for me now
I had to set
sonar.projectBaseDir
(and make sure master branch has built first using this configuration, otherwise it will have nothing to compare against).
I believe it affected us since we changed our yml build pipelines to pull from multiple repositories. When you have this, it appends the repo name in your checkout directory. This then creates the duplicated folder structure you see in SonarCloud and on the annotated PRs that the file is now “missing”.
We now use the SonarCloudPrepareConfiguration:
- task: SonarCloudPrepare@1
displayName: "Prepare SonarCloud"
inputs:
SonarCloud: '$(tfsSonarCloudServiceConnectionName)'
organization: '$(sonarCloudOrganisation)'
scannerMode: 'MSBuild'
projectKey: '$(projectName)'
projectName: '$(projectName)'
projectVersion: '$(Build.BuildNumber)'
extraProperties: |
sonar.exclusions=$(sonarCloudExclusions)
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
sonar.projectBaseDir=$(System.DefaultWorkingDirectory)/$(projectName)
condition: and(succeeded(), eq('${{ parameters.runDefaultSonarSteps }}', true) , or(eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/teams/')))
Where $(projectName)
for us is a build variable that matches both the repo name, and sonarcloud project name.
Hope this works for you!