Clarify the use of ``

My team found the usage of property confusing. They executed the following command on a fresh, previously never analyzed Git repo:

sonar-scanner ...

The result was:

ERROR: Project was never analyzed. A regular analysis is required before a branch analysis

While the documentation clearly says:

A branch is created when the parameter is passed during analysis.

It may not be so obvious, as it happened with us, thus I think there could be more emphasis in the documentation on the fact that we should never use the property for the main branch.

Thanks in advance.


i guess you’re still on Sonarqube 7.9.1 ?
This a known (annoying) shortcoming in this version with the use of in the
initial analysis. This is fixed in Sonarqube 8
But there’s a simple workaround.
Create a shared library for jenkins pipelines. It checks via Sonarqube web api for
project existence and - if it not exists already - create it. Call it before the analysis stage and all fine.
Otherwise you may create the project also manually via Sonarqube web ui before the analysis.


1 Like

The problem is caused that SQ tries to compare with the main branch. A very simple way to solve it is to not adding when you scan your main branch. Example in Jenkinsfile style:

sh """
    sonar-scanner ${branch != 'master' ? "${branch}" : ''} ... 

Thanks, @Rebse and @agabrys. Yes we’re still on SonarQube 7, and upgrading to 8 should be the solution then. And we’ll be using the suggested shell script as a workaround for now.