We use Azure DevOps and YAML pipelines to build and analyze our code.
This all works fine, except for the code that uses main
instead of master
as the default branch name. Then SonarQube emits a warning: Unable to get default branch, defaulting to 'master': TypeError: Cannot read property 'defaultBranch' of null
The warning is a false-positive. When I go to the SonarQube portal everything looks fine for the project and it even displays the default branch is main
.
We have a 'no warnings' policy, so it is very sad SonarQube is emitting this warning, which should be in my opinion Information
.
I think I need to instruct SonarQube not to look for the master
branch or tell it to also look for the main
branch. But I can't figure out how to do this. The documentation is not very helpful at this point.
This is my yaml task:
- task: SonarQubePrepare@5
displayName: Prepare analysis on SonarQube ($(SonarProjectKey))
inputs:
SonarQube: 'SonarQube - Developer Edition'
projectKey: $(SonarProjectKey)
projectName: '${{ parameters.AnalyseProjectName }}'
projectVersion: '$(Build.BuildNumber)'
extraProperties: |
sonar.verbose=true
sonar.branch.name=$(Build.SourceBranchName)
sonar.branch.target=main
sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
sonar.cs.vscoveragexml.reportsPaths=$(Agent.BuildDirectory)\TestResults\*.coveragexml
sonar.exclusions=**\Tests\**\*, **\TestApps\**\*, **\GlobalSuppressions.cs
If needed I can make changes to our build agents.
Please advise.
Following an extensive discussion with the SonarQube team, they have recently released a minor update to their Azure DevOps (AZDO) extension. I'm pleased to inform you that this new version has resolved the issue and no longer reports the warning.