We’re using Azure DevOps pipelines and GitHub with Sonarcloud.
When creating the Sonarcloud project, the master branch is created automatically, and it is marked as “main branch”. We also have our develop branch, and create feature branches off of it. When running the Azure DevOps build pipeline, Sonarcloud analysis succeeds, and the feature branches appear with analysis results in Sonarcloud. However, we notice that they are listed with the master branch as parent, not the develop branch. And it seems that the diff between the master branch and the feature branch is used for determining “new code” in the feature branch. So the feature branch gets “blamed” for more than it should. When we create pull requests, the develop branch is recognized as the parent, so this problem does not arise with pull requests.
We solved the parenting issue by setting “sonar.branch.target=develop” in the extraProperties of the SonarCloudPrepare step of our feature branch build pipeline. Unfortunately, it turned out that this was incompatible with pull requests, which turned up reporting
ERROR: A pull request analysis cannot have the branch analysis parameter 'sonar.branch.target'
As a workaround, we’ve deleted the existing develop branch and feature branches in Sonarcloud and renamed the master/main branch to “develop”. That seems to work for the feature branches and the develop branch (now, both feature branches and pull requests are children of the develop branch in Sonarcloud). But when analyzing the master branch, the analysis ends up being recorded in the develop branch (the default branch) in Sonarcloud. We’re not yet using the master branch or release branches actively, but it seems like this could become a major issue.
Is this a bug? Are we doing something wrong? How are the parent-child relations between branches captured?
We’ve set up our long living branches pattern as “(master|develop|release/).*”.