Bitbucket Cloud Maven scan fails with no project key or organization

Hello,

I’m trying to follow the Maven example from the documentation to set up a new SonarCloud scan using Bitbucket Pipeline. The example I’m following is here->https://bitbucket.org/sonarsource/sample-maven-project/src/master/

I have SONAR_TOKEN set up as a repository variable.

Here is my bitbucket-pipelines.yml:
image: maven:3.6.1

clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - maven
          - sonar
        script:
          - echo $SONAR_TOKEN
          - cd Project
          - mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
        artifacts:
          - target/**
    - step: &build-test
        name: Build and test
        caches:
          - maven
        script:
          - mvn -B verify
        artifacts:
          - target/**
pipelines:
  default:
    - step: *build-test-sonarcloud
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

This is failing with the following error:
[INFO] Bitbucket Cloud Pipelines detected

[INFO] User cache: /root/.sonar/cache

[INFO] SonarQube version: 8.0.0

[INFO] Default locale: "en", source code encoding: "UTF-8"

[INFO] Load global settings

[INFO] Load global settings (done) | time=588ms

[INFO] Server id: 86E9293D-KRHW8ct9-T_TB3XqobKk

[INFO] User cache: /root/.sonar/cache

[INFO] Load/download plugins

[INFO] Load plugins index

[INFO] Load plugins index (done) | time=137ms

[INFO] Load/download plugins (done) | time=26007ms

[INFO] Loaded core extensions: developer-scanner

[INFO] No project and organization key detected from Bitbucket Cloud Pipelines.

[INFO] Process project properties

Shouldn’t it be discovering the organization and project keys via the SONAR_TOKEN? Can someone point me in the right direction?

Thanks!

1 Like

Hi Andy, welcome to the forum!

I think the cause of this log message is that you imported the project on SonarCloud manually, instead of importing it through your Bitbucket account. If you used the latter method we can automatically resolve the project and organization key using your Bitbucket repository id. If the SonarCloud project is linked to your Bitbucket repository you should see a Bitbucket icon next to your project name in the project overview.

However the log line that your reference should be purely informational, and it should therefore not be the cause of the failure. Could it be that you defined the project and organization key in your sonar.properties file? Could you share the full output of your pipeline?

Thanks,
Tom

2 Likes