I’m new to sonarQube.
I did setup azure pipeline successfully with SonarQube. However I get main branch has no lines of code when I use azure devops scanner.
When I analyse the same repo with the SonarScanner the code lines appear in the web page.
I don’t know what I’m doing wrong:
Here is my azure pipeline
Hello @Roua_Mok
thanks for reaching out to the community with your question.
The difference in behavior between your command line analysis and your Azure Devops ones are due to the branch names that are set for them
The SonarScanner for Azure DevOps extension detects the branch name and sets it for the analysis (as main or develop or whatever is used on Azure Devops side)
you are leaving the parameter empty when using the SonarScanner command line and ‘master’ is the default when not set
SonarQube also uses ‘master’ as default main branch for every project on both SonarQube server side.
Your projects are seemingly better equipped when you run the command line analysis because you are on the (wrong) default name for your project main branch on both scanner and server sides.
To overcome the default use of ‘master’ as main branch, there are several things you might do:
Use SonarQube Azure Devops integration to create your projects. This will automatically align your project main branch name with the one set on Azure Devops side.
Always set the sonar.branch.name analysis parameter when you use the command line scanner for your tests
On existing projects, make sure the main branch of each SonarQube project is aligned with the one on Azure Devops. And it is important that you do so. For existing projects with ‘master’ wrongly used as main branch name, this will require you to:
delete the existing branch created on SonarQube with this name , e.g. delete the branch called ‘develop’ or ‘main’. This will cause the loss of all this branch data (history and issues)
rename the main branch of this project in SonarQube from ‘master’ to the right one (e.g. ‘main’ or ‘develop’)
reanalyze this branch from Azure Devops, or manually with the branch name parameter set