- ALM: Azure DevOps
- CI system: Azure DevOps
- Scanner command:
- task: SonarCloudPrepare@1
displayName: Prepare SonarCloud analysis configuration
inputs:
SonarCloud: SonarCloud
organization: $(sonarOrganization)
scannerMode: MSBuild
projectKey: $(sonarOrganization)_$(sonarProject)
projectName: $(sonarProject)
extraproperties:
sonar.exclusions=src/**/Resources/*
sonar.cpd.exclusions=**/Migrations/*,src/**Persistence/Migrations/*,src/*.DataSeeder/SeederImplementations/**
sonar.coverage.exclusions=**/Migrations/*,src/*.DataSeeder/**,src/*.Api/Program.cs,src/*.Domain/Exceptions/**Exception.cs,src/**Persistence/Migrations/*,src/**/Persistence/Migrations/*
sonar.coverageReportPaths="$(Build.SourcesDirectory)/coveragereport/SonarQube.xml"
// build
- task: SonarCloudAnalyze@1
condition: succeededOrFailed()
displayName: SonarCloud analyze
- task: SonarCloudPublish@1
displayName: SonarCloud publish Results
condition: succeededOrFailed()
inputs:
pollingTimeoutSec: '300'
- Languages: C#
- Error observed:
Sometimes we get a lot of pull requestion annotations from Sonar for some of our repositories. With “a lot” I mean all build warnings are commented, instead of just for “new code”.
Also the comments are created on the wrong path:
“This file no longer exists in the latest pull request changes. It may have been moved or deleted.”
It has a prefix /azp/_work/1/s/
, that shouldn’t be there (which is coming from the Azure Pipeline agent)
We only observed this issue in our Azure Function repos.
Today I could narrow it done one step more: it seems to be related to a specific nuget package reference.
I had at least three repositories with the following change:
Resulting in a lot of comments
Other PRs for those repositories didn’t have this issue.
EDIT: today we had other PRs with the same issue. It seems to be random.
I could even find the relevant part in the SonarCloud Analyze log:
PR with Issue:
INFO: Base dir: /
PR with no issue:
INFO: Base dir: /azp/_work/1/s
The PR build with issue also has the following warning
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
which makes sense, as the base path is already not correct, so it can find the correct source folder.
The PR build without the issue therefore has some of log statements, that are not in the log for the PR build with the issue like:
INFO: 7 files ignored because of scm ignore settings
...
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=148ms
which again makes sense and therefore resulting into the issue described above.
Either this is dependent on the build agent (don’t think so), or this is an issue in Sonar.
Any ideas?