Azure Devops default branches vs sonarcloud

Hi,

I’m not sure if this is somewhere in the documentation. But I couldn’t find anything about this issue we are experiencing. We are using SonarCloud for quite a few years now (together with Azure Devops) so we have built some nice history here.

For our ‘main’ branches we use a master (for production state) and dev (all our PRs are targetted to this branch). A few weeks ago someone in the organization changed our default and compare branch to the dev branch to optimize our PR creation flow:
image

The issue we are observing is that this action ‘detached’ the dev branch we have in SonarCloud. And who knows what is analyzed into the master branch in SonarCloud. (I’m suspecting both the dev and master branch)

I tried adding master to the long-lived branches: master|dev|experimental. But this isn’t helping getting the behavior we had like before.

Is there any setting or fix we can do to get the dev-branch connected to the dev-branch in SonarCloud again? And master to master? As I understand the ‘default’ branch in Azure Devops is picked up by SonarCloud as the master branch, can we override this maybe?

-Fred

Hello @FreddyGroen ,

Could you post a screenshot of the branches page of your project in SonarCloud? In addition, do you know how your CI/CD pipeline for SonarCloud is set up (e.g. are you using the tasks from the SonarCloud extension or something more custom)?

Hi @Martin_Bednorz ,

SonarCloud knows about these branches:

There are more release/xxx branches, these can be ignored.
Our current main branches are: master, dev and experimental. Are you can see the dev branch isn’t being updated anymore since the dev branch is marked ‘default’.

Our CI/CD pipeline is configured like this: (followed by a DotNetCoreCLI@2 build task)

      - task: SonarCloudPrepare@1
        displayName: "Prepare analysis configuration"
        inputs:
          scannerMode: "MSBuild"
          ... organization/projectkey and projectversion omitted

For completeness: we’re building our product on windows and linux agents and both show the same behavior.

I’m suspecting the ‘default’ branch from azure devops to be taken as ‘main branch’ in sonarcloud. But in our case we lost our master branch that was previously the default branch.

Best regards,
Freddy

(ps: I don’t mind using the community forum, but what can I do to speed up/prioritize issues like these?)

Thank you @FreddyGroen . I am looking at this with my colleagues and will get back to you as soon as possible.

There is no way to do this as of today. We are doing our best to prioritize and fix issues for our users and customers as quickly as possible.

1 Like

Hi @FreddyGroen

Sorry for the late reply here.

I think we found some sort of workaround here, let us know if that works.

In you dev build, make you that you fill in the sonar.branch.name=dev value in the extra properties of the Prepare analysis configuration task config. That way, it will override the default behavior to send results to master/main instead, you should be able to have them in your dev branch on SonarCloud.

Mickaël

Thanks! I’ll try that and will post an update here.

-Freddy

Hmm, this kind-of works… but gives me issues when running PR builds.

##[error]ERROR: Error during SonarScanner execution
ERROR: A pull request analysis cannot have the branch analysis parameter 'sonar.branch.name'

I’m not sure what a nice/clean solution for this issue would be. I’ll play around with this in our templates.
Is this issue something that I could fix in the SonarCloud ui at some point?

Freddy

Hi,

Yes indeed this will need to be fixed on our side and we’re already thinking about a good way to do it.

In your case, for PR, i would says that still the best way is to add Prepare task with condition, one for your default branch with that sonar.branch.name set and for PR/other branches you can let it without any branch name set, that should work.

Mickaël

1 Like