Azure DevOps Extension: Automatically setting sonar.branchname?

Hello,

we are running the Sonar Extension for Azure DevOps and it seems that the “SonarQubePrepare@4” task always setting the sonar.branchname property in the background. This is a problem if the project has not been published beforehand.

Is there a way to ommit this behaviour, trying to overwrite the property is also not working, e.g.: sonar.branch.name="" as the SONARQUBE_SCANNER_PARAMS then show:
"sonar.branch.name":"\"\""

Is there any workaround for this? Manually setting up the projects in sonarqube is no option, as we dont have the permissions to do so - and it shall be fully automated.

Here are the logs from sonar prepare:

    2020-02-17T16:06:32.0504146Z ##[section]Starting: Sonar Publish without branchname
    2020-02-17T16:06:32.0508387Z ==============================================================================
    2020-02-17T16:06:32.0508464Z Task         : Prepare Analysis Configuration
    2020-02-17T16:06:32.0508513Z Description  : Prepare SonarQube analysis configuration
    2020-02-17T16:06:32.0508828Z Version      : 4.9.0
    2020-02-17T16:06:32.0508875Z Author       : sonarsource
    2020-02-17T16:06:32.0508972Z Help         : Version: 4.9.0. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
    2020-02-17T16:06:32.0509031Z ==============================================================================
    2020-02-17T16:06:32.5982199Z SYSTEMVSSCONNECTION exists true
    2020-02-17T16:06:33.0956931Z ##[section]Finishing: Sonar Publish without branchname

And the configuration in the azure pipelines yml looks like this:

 - task: SonarQubePrepare@4
            condition: eq('${{ parameters.disable_sonar_branch_publishing }}', false)
            inputs:
              SonarQube: "SonarQube"
              scannerMode: "CLI"
              configMode: "file"
              configFile: $(System.DefaultWorkingDirectory)/sonar-project.properties
              extraProperties: |
                # Put one key=value per line, example:
                  sonar.branch.name="" # if i leave this out, it is automatically prefilled...
                  sonar.verbose=true
                  sonar.projectBaseDir=$(System.DefaultWorkingDirectory)
                  sonar.projectVersion=$(package_version)
                  sonar.projectName$(package_name)
            displayName: "Sonar Publish without branchname"

SonarScannerTask logs:

2020-02-17T16:06:33.2546460Z ##[section]Starting: SonarQubeAnalyze
2020-02-17T16:06:33.2549758Z ==============================================================================
2020-02-17T16:06:33.2549840Z Task         : Run Code Analysis
2020-02-17T16:06:33.2549904Z Description  : Run scanner and upload the results to the SonarQube server.
2020-02-17T16:06:33.2550012Z Version      : 4.9.0
2020-02-17T16:06:33.2550070Z Author       : sonarsource
2020-02-17T16:06:33.2550235Z Help         : Version: 4.9.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
2020-02-17T16:06:33.2550326Z ==============================================================================
2020-02-17T16:06:33.4172544Z [command]/home/my_agent/agent/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/4.9.0/sonar-scanner/bin/sonar-scanner
2020-02-17T16:06:33.5116756Z INFO: Scanner configuration file: /home/my_agent/agent/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/4.9.0/sonar-scanner/conf/sonar-scanner.properties
2020-02-17T16:06:33.5117613Z INFO: Project root configuration file: /home/my_agent/agent/_work/22/s/sonar-project.properties
2020-02-17T16:06:33.5514070Z 17:06:33.549 INFO: SonarQube Scanner 4.2.0.1873
2020-02-17T16:06:33.5517100Z 17:06:33.551 INFO: Java 11.0.6 Ubuntu (64-bit)
2020-02-17T16:06:33.5517659Z 17:06:33.551 INFO: Linux 4.15.0-72-generic amd64

.....
.....

2020-02-17T16:06:35.6264884Z 	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
2020-02-17T16:06:35.6265091Z 	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
2020-02-17T16:06:35.6265161Z 	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
2020-02-17T16:06:35.6265299Z 	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
2020-02-17T16:06:35.6265403Z 	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
2020-02-17T16:06:35.6265520Z 	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
2020-02-17T16:06:35.6265737Z ##[error]... 34 more
Caused by: Project was never analyzed. A regular analysis is required before a branch analysis
2020-02-17T16:06:35.6265959Z 	... 34 more
2020-02-17T16:06:35.6266064Z Caused by: Project was never analyzed. A regular analysis is required before a branch analysis
2020-02-17T16:06:35.6266227Z ##[error]17:06:35.617 ERROR:
2020-02-17T16:06:35.6266421Z 17:06:35.617 ERROR:

Hi @cpolzer,

This is problematic since we strongly encourage to create the project on SonarCloud before analyzing it (we don’t have yet strong binding between project and repos for AzDo, but that will be the case in the near future, as we do for other ALMs).

Is there a particular use case that lead to not provision the project before ?

Thanks.
Mickaël

Hello,

yes, this is all happening in a corporate SonarQube Enterprise setup…