Could not find a default branch to fall back on - Maven Build

I am creating a new azure pipeline which builds an apigee proxy using maven & I am trying to integrate sonar into the build process. I’ve struggled to find clear documentation in what is required so hoping I can get some guidance.

The pipeline keeps failing with the following:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project proxy-name: Could not find a default branch to fall back on. → [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project proxy-name: Could not find a default branch to fall back on.
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:306)

The pipeline looks something like this:

  • task: SonarCloudPrepare@1
    condition: ${{variables.runSonarAnalysis}}
    inputs:
    SonarCloud: ‘sonarcloud’
    organization: ‘test-org’
    scannerMode: ‘Other’
    projectKey: ${{ parameters.sonarProjectKey }}
    projectName: ${{ parameters.sonarProjectName }}
    extraProperties: |
    sonar.projectVersion=$(Build.BuildNumber)
    sonar.cs.vstest.reportsPaths=$(System.DefaultWorkingDirectory)/**/coverage

  • task: Maven@3
    displayName: ‘Maven Build n Package’
    condition: and(variables[‘runSonarAnalysis’], or(succeeded(), contains(variables[‘unit_test_out.UnitTestingvariable’], false)))
    inputs:
    mavenPomFile: ‘pom.xml’
    goals: ‘package -P deploy’
    options: ‘-Dorg=test-org -e’
    publishJUnitResults: false
    javaHomeOption: ‘JDKVersion’
    mavenVersionOption: ‘Default’
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: true
    sqMavenPluginVersionChoice: ‘latest’

Can anyone point me in the right direction?

Hi,

Welcome to the community!

Does this project already exist on SonarCloud with the project key set to the value of ${{ parameters.sonarProjectKey }}?

 
Ann

Hi and thank you for the welcome.

Yes the project does already exists in sonarcloud & I have confirmed the key and name matches those variables.
I have tried creating the project manually in sonar as well as onboarding but neither seem to work.

Hey there.

There’s an unfortunately long-standing bug in the tutorial for configuring analysis with Maven + Azure DevOps.

This means a configuration that looks more like this:

- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud'
    organization: 'colin-sonarsource'
    scannerMode: 'Other'
    extraProperties: |
      # Additional properties that will be passed to the scanner, 
      # Put one key=value per line, example:
      # sonar.exclusions=**/*.bin
      sonar.projectKey=my-sonarcloud-generated-project-key

- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: true
    sqMavenPluginVersionChoice: 'latest'
1 Like

Can you explain the difference between your solution and the one In my initial post?
Looks almost identical and still encountering an issue…

Hey there.

The difference comes from defining sonar.projectKey under extraProperties rather than as a projectKey which does nothing in the context of the Other scanner mode.

1 Like

Yep - that worked!
Thank you Colin for taking the time to explain - means a lot.

1 Like

Thanks for your patience! On my side, I’m pushing for a more accurate tutorial. :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.