Create SonarQube Project

Action ID: sonarqube:create-project
NPM Package:

@backstage-community/plugin-scaffolder-backend-module-sonarqube

Description

Creates a new project in SonarQube

Input Schema

PropertyTypeDescriptionRequired
keystring-
namestring-
tokenstring-
branchstring-
baseUrlstring-
passwordstring-
usernamestring-
visibilitystring-

Output Schema

PropertyTypeDescriptionRequired
projectUrlstring-

Usage Examples

Create a private SonarQube project with token authentication

Creates a private SonarQube project for a new service using a personal access token. Use this when provisioning a service that will be analyzed in a self hosted SonarQube instance.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: ./
      values:
        serviceName: ${{ parameters.serviceName }}
        owner: ${{ parameters.owner }}

  - id: create-sonarqube-project
    action: sonarqube:create-project
    input:
      baseUrl: https://sonarqube.acme.corp
      name: payments-service
      key: acme.payments-service
      branch: main
      visibility: private
      token: ${{ secrets.sonarqubeToken }}

  - id: log-sonar-url
    action: debug:log
    input:
      message: SonarQube project URL ${{ steps.create-sonarqube-project.output.projectUrl }}

Create a public project using username and password

Creates a public project in an on prem SonarQube using basic authentication. Use this when token authentication is not available.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: ./
      values:
        serviceName: ${{ parameters.componentName }}
        owner: ${{ parameters.owner }}

  - id: create-sonarqube-project
    action: sonarqube:create-project
    input:
      baseUrl: http://sonarqube.internal:9000
      name: docs-portal
      key: acme.docs-portal
      branch: develop
      visibility: public
      username: ci-bot
      password: ${{ secrets.sonarqubePassword }}

  - id: log-sonar-url
    action: debug:log
    input:
      message: SonarQube project URL ${{ steps.create-sonarqube-project.output.projectUrl }}

Create a project with values from template parameters

Creates a project where the name, key, and base URL come from template parameters. Use this when different environments have different SonarQube hosts.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: ./
      values:
        serviceName: ${{ parameters.componentName }}
        description: ${{ parameters.description }}

  - id: create-sonarqube-project
    action: sonarqube:create-project
    input:
      baseUrl: ${{ parameters.sonarqubeBaseUrl }}
      name: ${{ parameters.componentName }}
      key: acme.${{ parameters.repoName }}
      branch: release-1.0
      visibility: private
      token: ${{ secrets.sonarqubeToken }}

  - id: log-sonar-url
    action: debug:log
    input:
      message: Created project at ${{ steps.create-sonarqube-project.output.projectUrl }}

Conditionally create a project when SonarQube is enabled

Creates a SonarQube project only if a template parameter is enabled. Use this to make code scanning optional.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: ./
      values:
        serviceName: ${{ parameters.name }}
        owner: ${{ parameters.owner }}

  - id: create-sonarqube-project
    if: ${{ parameters.enableSonarqube }}
    action: sonarqube:create-project
    input:
      baseUrl: https://sonarqube.acme.corp
      name: ${{ parameters.name }}
      key: acme.${{ parameters.name }}
      branch: main
      visibility: private
      token: ${{ secrets.sonarqubeToken }}

  - id: log-sonar-url
    if: ${{ parameters.enableSonarqube }}
    action: debug:log
    input:
      message: SonarQube project URL ${{ steps.create-sonarqube-project.output.projectUrl }}

Create separate projects for a monorepo frontend and backend

Creates two SonarQube projects to analyze frontend and backend code independently. Use this in monorepos where each part has its own quality gates.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: ./
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}

  - id: create-frontend-project
    action: sonarqube:create-project
    input:
      baseUrl: https://sonarqube.acme.corp
      name: web-frontend
      key: acme.web-frontend
      branch: main
      visibility: private
      token: ${{ secrets.sonarqubeToken }}

  - id: create-backend-project
    action: sonarqube:create-project
    input:
      baseUrl: https://sonarqube.acme.corp
      name: api-backend
      key: acme.api-backend
      branch: trunk
      visibility: private
      token: ${{ secrets.sonarqubeToken }}

  - id: log-sonar-urls
    action: debug:log
    input:
      message: Frontend ${{ steps.create-frontend-project.output.projectUrl }} Backend ${{ steps.create-backend-project.output.projectUrl }}