When I try to analyze my project using sonar-scanner, the scan fails with the following error message:
Caused by: Branch does not exist on server: develop
Apparently, this only happens when it analyzes a Pull Request from GitHub. I could reproduce the error, when I add the following configuration to sonar-project.properties
:
sonar.branch.name = source-branch
sonar.branch.target = target-branch
What could be the cause for this problem?
I solved the problem by deleting my Sonar project that was watching the develop
branch. Then I added the develop
branch as a long-living branch to the Sonar project analyzing the master
branch. Before, I had a Sonar project for each long-living branch, because I was using the branches
property in travis.yml
(which is getting deprecated now).
To add a new branch to Sonarqube you need to add the sonar.branch.name
property with the name of the desired branch to the sonar-project.properties
file. E.g.: sonar.branch.name=develop
Then you run sonar-scanner
and your branch will be available inside the Sonar-Project.*
* Make sure to check if the Regex for long-living branches is appropriate to your new branch on Sonarqube. You can't change a long-living branch to a short-living branch or vice-versa after the branch is added to Sonarqube.
The result is that I have only one project on Sonarqube now that watches all my branches. It's a lot cleaner and works better.
More information on the branch plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With