Publish To Bitbucket

Action ID: publish:bitbucket
NPM Package:

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

Description

Initializes a git repository of the content in the workspace, and publishes it to Bitbucket.

Input Schema

PropertyTypeDescriptionRequired
tokenstringThe token to use for authorization to BitBucket
repoUrlstringRepository Location
enableLFSbooleanEnable LFS for the repository. Only available for hosted Bitbucket.
signCommitbooleanSign commit with configured PGP private key
sourcePathstringPath within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.
descriptionstringRepository Description
defaultBranchstring-
gitAuthorNamestring-
gitAuthorEmailstring-
repoVisibilitystring-
gitCommitMessagestring-

Output Schema

PropertyTypeDescriptionRequired
remoteUrlstringA URL to the repository with the provider
commitHashstringThe git commit hash of the initial commit
repoContentsUrlstringA URL to the root of the repository

Usage Examples

Publish a private Bitbucket Cloud repo with custom commit metadata

Creates a private repository on Bitbucket Cloud with main as the default branch. After fetching the template with fetch:template it publishes the generated code and sets commit author details.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/acme-org/software-templates/tree/main/templates/service-skeleton
      values:
        name: ${{ parameters.serviceName }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}

  - id: publish-repo
    action: publish:bitbucket
    input:
      repoUrl: bitbucket.org?workspace=acme-ws&project=ENG&repo=${{ parameters.serviceName }}
      description: ${{ parameters.description }}
      repoVisibility: private
      defaultBranch: main
      gitCommitMessage: "chore: initial scaffold for ${{ parameters.serviceName }}"
      gitAuthorName: "Jane Doe"
      gitAuthorEmail: "jane.doe@acme.com"

Publish a subdirectory to a public repo using a token and register in the catalog

Publishes only the services/api folder as the repository root to a public Bitbucket Cloud repo using a personal access token. After publishing it registers the component with catalog:register.

Copy
steps:
  - id: fetch-template
    action: fetch:template
    input:
      url: https://github.com/acme-org/software-templates/tree/main/templates/multiservice
      values: ${{ parameters }}

  - id: publish-api
    action: publish:bitbucket
    input:
      repoUrl: bitbucket.org?workspace=acme-ws&project=ENG&repo=${{ parameters.apiName }}
      description: "Public API for payments"
      repoVisibility: public
      defaultBranch: develop
      sourcePath: services/api
      token: ${{ secrets.bitbucketToken }}
      gitCommitMessage: "feat: bootstrap API service"
      gitAuthorName: "Service Generator"
      gitAuthorEmail: "scaffolder@acme.com"

  - id: register
    action: catalog:register
    input:
      catalogInfoUrl: ${{ steps.publish-api.output.repoContentsUrl }}/catalog-info.yaml

Enable Git LFS and sign the initial commit

Enables Git LFS support and signs the initial commit for repositories hosted on Bitbucket Cloud. Use this when the template includes large binary assets in the assets directory and you want signed commits.

Copy
steps:
  - id: fetch-assets
    action: fetch:template
    input:
      url: https://github.com/acme-org/software-templates/tree/main/templates/ml-model
      values:
        name: ${{ parameters.modelName }}
        owner: ${{ parameters.owner }}

  - id: publish-with-lfs
    action: publish:bitbucket
    input:
      repoUrl: bitbucket.org?workspace=acme-ws&project=DS&repo=${{ parameters.modelName }}
      description: "ML model artifacts and serving code"
      repoVisibility: private
      defaultBranch: main
      sourcePath: assets
      enableLFS: true
      signCommit: true
      token: ${{ secrets.bitbucketToken }}
      gitCommitMessage: "build: initial model drop with LFS"
      gitAuthorName: "CI Bot"
      gitAuthorEmail: "ci@acme.com"

Publish to self hosted Bitbucket Server with project key

Publishes to an on premises Bitbucket Server using a project key. This uses a token for authentication and logs the created repository URL with debug:log.

Copy
steps:
  - id: fetch-service
    action: fetch:template
    input:
      url: https://github.com/acme-org/software-templates/tree/main/templates/java-service
      values: ${{ parameters }}

  - id: publish-server
    action: publish:bitbucket
    input:
      repoUrl: bitbucket.acme.corp?project=PLAT&repo=${{ parameters.repoName }}
      description: "Platform service for internal use"
      defaultBranch: main
      token: ${{ secrets.bbServerToken }}
      gitCommitMessage: "chore: scaffold ${{ parameters.repoName }}"
      gitAuthorName: "Backstage Bot"
      gitAuthorEmail: "backstage-bot@acme.corp"

  - id: log-remote
    action: debug:log
    input:
      message: "Repository created at ${{ steps.publish-server.output.remoteUrl }}"

Custom default branch and output usage in follow up steps

Creates a private repo with a custom default branch release and then logs the commit hash. Use this to wire outputs from publish into later steps such as notifications or tagging with debug:log.

Copy
steps:
  - id: fetch-app
    action: fetch:template
    input:
      url: https://github.com/acme-org/software-templates/tree/main/templates/node-service
      values:
        name: ${{ parameters.appName }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}

  - id: publish-app
    action: publish:bitbucket
    input:
      repoUrl: bitbucket.org?workspace=acme-ws&project=OPS&repo=${{ parameters.appName }}
      description: ${{ parameters.description }}
      repoVisibility: private
      defaultBranch: release
      gitCommitMessage: "feat: bootstrap ${{ parameters.appName }}"
      gitAuthorName: "DevEx Team"
      gitAuthorEmail: "devex@acme.com"

  - id: log-commit
    action: debug:log
    input:
      message: "Initial commit ${{ steps.publish-app.output.commitHash }} pushed to ${{ steps.publish-app.output.remoteUrl }}"