Jenkins job is Successful but on SonarCloud shows "The main branch of this project is empty"

Using SonarCloud and trying to analyze a GitHub repo via Jenkins Job.
Jenkins job is Successful but on SonarCloud shows “The main branch of this project is empty”

Hi @paree ,

Which Git branch did you analyze, and which branch is set as the default branch in your SonarCloud project?

Hi Chris,
It is master branch.

Hi paree,

You may have to elaborate on that answer :slight_smile:

Did you analyze the master branch?
Is master set as the default branch for this project in SonarQube?

Typically you’re getting this message when you’ve analyzed a branch that’s not the default branch. When you click on the branch dropdown in SonarQube, which branches do you see?

Hi Chris,
Thanks for the response. I see only one branch under my project, master . please check the screenshot.

Thanks for the screenshot!

This looks like the scan was successful 17 hours ago. If you’re still getting the message “The main branch of this project is empty” then no code was sent to SonarQube as part of the scan. Can you please double-check the path in the SonarQube configuration of the scan, and whether any exclusions are set, either in the scan configuration or the SonarQube configuration?

Hi Chris,
Whenever I run the Jenkins Job, it does show scan was successful, but still shows “The main branch of this project is empty” when I go in it shows bugs etc but ‘0 lines’ of code analyzed.
If path is incorrect will it show these details of successful scan etc and also on my jenkins console output, it does show URL to check the scan analysis and when I click, it brings to my same project page.

Rgdg, configuration, I am not not sure what exactly is a mistake /need to add in my pipeline script as I already put -Dsonar.branch.name=master

Hope this helps to understand the issue. Appreciate your time!

Yes, if the path is incorrect it will show exactly what you’re seeing. Basically, Jenkins sent zero lines of code to SonarQube to analyze. SonarQube analyzed those zero lines successfully, and found no bugs there. Everything is doing what it’s supposed to do, except that no code is involved.

You’ll need to figure out why Jenkins doesn’t send any code. The most likely cause is that the code path in Jenkins isn’t set correctly for the scan. Or - if this is e.g. a .NET project and you’re integrating the scan with MSBuild, you need to set up the scan, then build the project, and then send the code analysis to SonarQube. If the order is different you’ll also see no code being analyzed. Either way, the issue is likely on the Jenkins side.