Creating a branch and compare against master

We are using the Developer Edition and I am tasked with integrating branch analysis.

Our workflow is simple: we have the master branch which is the stable branch. For each change, a new branch is created. These are (usually) short-lived. We now run sonar-scanner on that branch with sonar.branch.name set to the branch’s name (e.g. sonar-scanner -Dsonar.branch.name=task123). This results in SonarQube showing an additional branch in the web interface.

However, that branch does not show / analyze the delta to the master branch (I even tried explicitly giving sonar.branch.target=master). I seem to be only able to analyze updates within that branch, but can not trigger a delta analysis to the master branch.

Reproduction:

INFO: SonarQube Scanner 4.2.0.1873
INFO: SonarQube server 8.1.0

  • git checkout -b task123
  • <edit a source file, e.g. add int i, j; in a .cpp>
  • git commit -a . -m “test”
  • sonar-scanner -Dsonar.branch.target=master -Dsonar.branch.name=task123
    -> This results in a branch task123 on SonarQube, but no “New Code” is shown
  • run again: sonar-scanner -Dsonar.branch.target=master -Dsonar.branch.name=task123
    -> This now shows New Code, but with everything 0.
  • <edit a source file, e.g. extend to int i, j, k; in a .cpp>
  • git commit -a . -m “test2”
  • sonar-scanner -Dsonar.branch.target=master -Dsonar.branch.name=task123
    -> This now shows New Code, and adds the code smell for variable k.

What I would expect is a “New code” compared against master branch on first submission (in this case, complaining about i, j and k variables being in the same line and not const, for example)

Hi,

is not relevant anymore for Sonarqube 8.1
We have related problems, see

and

Gilbert

1 Like

Thanks, Gilbert. That’s exactly the situation I have. I guess I will follow your threads (already voted for the request) and hope that they are going to fix it.

I met the same demand as you, how can I achieve it?
Thanks

@xiaoweiFive, see the linked threads.

Basically I am not scanning the branches as branches anymore, but as pull-requests.

I need to pull-request every time I submit the code, or do I use sonar to create pull-requests?
please help me
Thanks!

hi, Link is error! :joy: