Strange Sonar Scanner behaviour for NET6 on branch

We started to use SonarCloud with Bitbucket cloud. For build server we use Windows Server VM, because some of the projects are still .net framework.

I created pipeline for NET6, C# project:

- step: &build
        name: "Build"
          - "self.hosted"
          - "windows"
           - 'dotnet sonarscanner begin /o:"xxx" /k:"xxx" /"" /d:sonar.login=$env:SONAR_TOKEN'
           - 'dotnet build ".\xxx\xxx.sln" --configuration Release'
           - 'dotnet sonarscanner end /d:sonar.login=$env:SONAR_TOKEN'

    - step: *build

SonarScanner for MSBuild 5.6

When running as bitbucket pipeline on feature branch, the analysis shows 0 new lines, everytime.I see a warning in the corner: “Could not find ref ‘master’ in refs/heads, refs/remotes/upstream or refs/remotes/origin. You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.”

I see in the log:

INFO: Roslyn version:
INFO: Language version: CSharp10
INFO: Concurrent execution: enabled
INFO: Sensor C# Analysis Log [csharp] (done) | time=2ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=3ms
INFO: Sensor Text Sensor [text]
INFO: 48 source files to be analyzed
INFO: 48/48 source files have been analyzed

When I run the same command on local windows machine, but with /“feature/xxx-123”, I can see the number of lines, but no analysis is performed. I checked .sonarqube/out/6/issues.json file, and see issues there, but nothing is shown on the website.

Why so random results? How can I make it more stable and accurate?


This thread may help:


Unfortunately it’s not helpful. When I executed analysis locally, I had master branch fetched.