Ensure GitLab Group Exists

Action ID: gitlab:group:ensureExists
NPM Package:

@backstage/plugin-scaffolder-backend-module-gitlab

Description

Ensures a Gitlab group exists

Input Schema

PropertyTypeDescriptionRequired
patharrayA path of group names or objects (name and slug) that is ensured to exist
tokenstringThe token to use for authorization to GitLab
repoUrlstring-

Output Schema

PropertyTypeDescriptionRequired
groupIdnumberThe id of the innermost sub-group

Usage Examples

Ensure a parent and sub-group on a self-hosted GitLab instance

Ensures the group path platform/demo-services exists on a self-hosted GitLab. Use this when publishing projects into that namespace with token-based auth.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .

  - id: ensure-groups
    action: gitlab:group:ensureExists
    input:
      repoUrl: gitlab.internal.example.com?owner=platform%2Fdemo-services&repo=${{ parameters.repoName }}
      token: ${{ secrets.gitlabToken }}
      path:
        - platform
        - demo-services

  - id: publish
    action: publish:gitlab
    input:
      repoUrl: gitlab.internal.example.com?owner=platform%2Fdemo-services&repo=${{ parameters.repoName }}
      description: ${{
        parameters.description
      }}

Parameterized org and team groups on GitLab.com

Creates an organization and team group path derived from template parameters. Use this when teams are supplied as inputs during scaffolding.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .

  - id: ensure-org-team
    action: gitlab:group:ensureExists
    input:
      repoUrl: gitlab.com?owner=${{ parameters.orgSlug }}%2F${{ parameters.teamSlug }}&repo=${{ parameters.repoName }}
      path:
        - ${{ parameters.orgSlug }}
        - ${{ parameters.teamSlug }}

  - id: publish
    action: publish:gitlab
    input:
      repoUrl: gitlab.com?owner=${{ parameters.orgSlug }}%2F${{ parameters.teamSlug }}&repo=${{ parameters.repoName }}
      defaultBranch: main

Ensure only a top-level group before creating repos

Ensures a single top-level group exists. Use this when all projects for a domain are created directly under the top-level namespace.

Copy
steps:
  - id: ensure-root-group
    action: gitlab:group:ensureExists
    input:
      repoUrl: gitlab.com?owner=data-platform&repo=${{ parameters.repoName }}
      path:
        - data-platform

  - id: publish
    action: publish:gitlab
    input:
      repoUrl: gitlab.com?owner=data-platform&repo=${{ parameters.repoName }}
      repoVisibility: internal

Ensure a deep nested path for environment-specific namespaces

Ensures the multi-level path acme/payments/settlement/dev exists. Use this when separating projects by product and environment.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .

  - id: ensure-env-path
    action: gitlab:group:ensureExists
    input:
      repoUrl: gitlab.com?owner=acme%2Fpayments%2Fsettlement%2Fdev&repo=${{ parameters.repoName }}
      token: ${{ secrets.gitlabToken }}
      path:
        - acme
        - payments
        - settlement
        - dev

  - id: publish
    action: publish:gitlab
    input:
      repoUrl: gitlab.com?owner=acme%2Fpayments%2Fsettlement%2Fdev&repo=${{ parameters.repoName }}
      contributors:
        - ${{
            user.entity.metadata.name
          }}

Target different GitLab hosts based on environment

Ensures a consistent platform/tools group path on the GitLab host chosen by a template parameter. Use this for multi-instance or multi-region setups.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .

  - id: ensure-multi-host-group
    action: gitlab:group:ensureExists
    input:
      repoUrl: ${{ parameters.gitlabHost }}?owner=platform%2Ftools&repo=${{ parameters.repoName }}
      path:
        - platform
        - tools

  - id: publish
    action: publish:gitlab
    input:
      repoUrl: ${{ parameters.gitlabHost }}?owner=platform%2Ftools&repo=${{ parameters.repoName }}
      protectDefaultBranch: true