Create Bitbucket Branch Restrictions

Action ID: bitbucketCloud:branchRestriction:create
NPM Package:

@backstage/plugin-scaffolder-backend-module-bitbucket-cloud

Description

Creates branch restrictions for a Bitbucket Cloud repository.

Input Schema

No input schema defined for this action.

Output Schema

PropertyTypeDescriptionRequired
jsonstringThe response from bitbucket cloud
statusCodenumberThe status code of the response

Usage Examples

Require approvals before merging to main

Creates a branch restriction that requires two approvals before merging into main. Use this right after creating the repository with publish:bitbucketCloud.

Copy
steps:
  - id: fetch-base
    name: Fetch service template
    action: fetch:template
    input:
      url: https://github.com/acme/templates/node-service
      targetPath: ./

  - id: require-approvals-main
    name: Require approvals on main
    action: bitbucketCloud:branchRestriction:create
    input:
      repoUrl: bitbucket.org?workspace=${{ parameters.workspace }}&repo=${{ parameters.repoSlug }}
      kind: require_approvals_to_merge
      matcher:
        kind: glob
        pattern: main
      value: ${{ parameters.requiredApprovals }}

Prevent force pushes to release branches

Blocks force pushes to any release/* branches to protect release history. Use this after the repo is created, typically following publish:bitbucketCloud, to enforce guardrails on long-lived branches.

Copy
steps:
  - id: fetch-base
    name: Fetch base template
    action: fetch:template
    input:
      url: https://github.com/acme/templates/java-service
      targetPath: ./

  - id: protect-release-branches
    name: Block force pushes on release/*
    action: bitbucketCloud:branchRestriction:create
    input:
      repoUrl: bitbucket.org?workspace=${{ parameters.workspace }}&repo=${{ parameters.repoSlug }}
      kind: force
      matcher:
        kind: glob
        pattern: release/*