Pass branch info to SonarScanner


currently the my Sonar Github Action is triggered when the previous Build Action is finished successfully.
Yet, it seems this way of running the sonarScanner breaks the automatic branch detection, which results in mixing up the analysis result of analysed branch with main branch.

So, is there any way to pass information about the branch that’s actually analyzed to the scanner?
Or how does the autodetection actually work?

The setup is the following:

  • GitHub
  • Java with maven


After some more digging and luckily finding a blog post referencing the relevant SonarQube docs, i was able to achive the desired behavior.

To make it work I passed these params to the scanner

-Dsonar.pullrequest.branch='${{ github.event.workflow_run.head_branch }}'

pullrequest.key was a fixed value for testing purposes but it should be possible to find it somewhere in the context.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.