Analyze new project via bitbucket pipelines

I’d like to find the way to analyze new sonar project automatically via pipeline without manually create from the UI, is it possible ?

current configuration:

  • SONAR_TOKEN is valid → generate and check from security page
  • ALM used Bitbucket Cloud
  • CI system used Bitbucket Cloud
  • Scanner command used
    - step: &scan
        image: node:20
        name: Build, test and analyze on SonarCloud
        size: 2x
        caches:
          - node
          - sonar
        script:
          - npm ci
          - npm run build
          - pipe: sonarsource/sonarcloud-scan:4.1.0
            variables:
              SONAR_PROJECT_KEY: $BITBUCKET_REPO_SLUG
              EXTRA_ARGS: [
                '-Dsonar.exclusions=node_modules/**,**/tests/**,**/*.spec.ts,**/*.test.ts',
                '-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info',
                '-Dsonar.typescript.tsconfigPath=tsconfig.json',
                '-Dsonar.javascript.node.maxspace=7168',
                '-Dsonar.organization=xxxxx'
              ]
              SONAR_SCANNER_OPTS: "-Xmx7168m"
        
  • Languages of the repository typescript
  • Error
08:40:22.993 INFO  Load/download plugins (done) | time=1439ms
08:40:23.487 INFO  Found an active CI vendor: 'Bitbucket Pipelines'
08:40:23.635 INFO  No project and organization key detected from Bitbucket Cloud Pipelines.
08:40:23.639 INFO  Load project settings for component key: 'xxxxx'
08:40:23.781 INFO  Process project properties
08:40:23.782 INFO  Execute project builders
08:40:23.783 INFO  Execute project builders (done) | time=0ms
08:40:23.785 INFO  Project key: xxxxx
08:40:23.785 INFO  Base dir: /opt/atlassian/pipelines/agent/build
08:40:23.786 INFO  Working dir: /opt/atlassian/pipelines/agent/build/.scannerwork
08:40:23.793 INFO  Load project branches
08:40:23.984 INFO  Load project branches (done) | time=191ms
08:40:23.987 INFO  Check ALM binding of project 'xxxxx'
08:40:24.125 INFO  Detected project binding: NONEXISTENT
08:40:24.126 INFO  Check ALM binding of project 'xxxxx' (done) | time=139ms
08:40:24.129 INFO  Load project pull requests
08:40:24.269 INFO  Load project pull requests (done) | time=140ms
08:40:24.273 INFO  Load branch configuration
08:40:24.275 INFO  Detected analysis for branch 'main'
08:40:24.277 INFO  Auto-configuring branch main
08:40:24.315 ERROR Could not find a default branch for project with key 'xxxxx'. Make sure project exists.
08:40:24.648 INFO  EXECUTION FAILURE
08:40:24.651 INFO  Total time: 12.385s

Hey there.

Does the user whose token you are providing for analysis have the Create Proejcts permission?

Yes, the token is generated from Admin account (with all permissions)