Skip to main content

Bitbucket Cloud Discovery

The Bitbucket Cloud integration has a special entity provider for discovering catalog files located in Bitbucket Cloud. The provider will search your Bitbucket Cloud account and register catalog files matching the configured path as Location entity and via following processing steps add all contained catalog entities. This can be useful as an alternative to static locations or manually adding things to the catalog.

Event-based Discovery​

Supported events for event-based updates:

  • repo:push received as bitbucket.repo:push
  • repo:updated received as bitbucket.repo:updated
    • Changes are triggered if the repository slug/name changed, causing a new URL for it.

To receive events, you need to add webhook subscriptions at Bitbucket Cloud. Enable the triggers (event types) you want to receive. For the entity provider, only the event types above are supported ("Repository Push" and/or "Repository Updated") and additional event types will be ignored (e.g., for other use cases/integrations you might have).

For more information on how to set up the event-based discovery, see the installation instructions below.

Installation​

You will have to add the entity provider in the catalog initialization code of your backend. The provider is not installed by default, therefore you have to add a dependency to @backstage/plugin-catalog-backend-module-bitbucket-cloud to your backend package.

From your Backstage root directory
yarn --cwd packages/backend add @backstage/plugin-catalog-backend-module-bitbucket-cloud

Then add the following to your backend:

packages/backend/src/index.ts
// optional if you want HTTP endpoints to receive external events
// backend.add(import('@backstage/plugin-events-backend'));
// optional if you want to use AWS SQS instead of HTTP endpoints to receive external events
// backend.add(import('@backstage/plugin-events-backend-module-aws-sqs'));
backend.add(import('@backstage/plugin-events-backend-module-bitbucket-cloud'));
backend.add(import('@backstage/plugin-catalog-backend-module-bitbucket-cloud'));

You need to decide how you want to receive events from external sources like

Further documentation:

Configuration​

To use the entity provider, you'll need a Bitbucket Cloud integration set up.

The entity provider uses the workspace code search API of Bitbucket Cloud when the integration credential can call it. That API needs a credential that identifies a user, for example a username (your Atlassian account email) and an API token with the scopes read:repository:bitbucket and read:workspace:bitbucket. An API token is the faster choice for a large workspace, because one search covers the workspace.

Bitbucket Cloud answers 403 for credentials that do not identify a user. That includes an OAuth consumer (clientId and clientSecret), an app password, and an API key. An API token without the read:workspace:bitbucket scope also answers 403. Adding that scope restores workspace code search. It answers 404 when code search is not enabled for the workspace. Discovery then lists the matching repositories and checks the catalog path with the source API, which accepts the same credentials as the rest of the integration. An absolute catalog path such as /catalog-info.yaml is one request per repository. A wildcard path walks from the longest directory prefix with no * or ?. For example, /services/*/catalog-info.yaml lists services and skips unrelated directories. A relative path, and an absolute path with a wildcard in the first segment such as /catalog-*.yaml, still walks from the repository root. Relative and wildcard catalogPath values are expensive in source API fallback mode on a large workspace: each repository is walked separately, so thousands of repositories can make discovery slow or receive 429 responses. Prefer an absolute catalog path, or an API token that includes read:workspace:bitbucket, when the workspace is large. A prefix that is missing, or a file at that prefix, adds no locations.

Additionally, you need to configure your entity provider instance(s):

app-config.yaml
catalog:
providers:
bitbucketCloud:
yourProviderId: # identifies your ingested dataset
catalogPath: /catalog-info.yaml # default value
filters: # optional
projectKey: '^apis-.*$' # optional; RegExp
repoSlug: '^service-.*$' # optional; RegExp
schedule: # same options as in SchedulerServiceTaskScheduleDefinition
# supports cron, ISO duration, "human duration" as used in code
frequency: { minutes: 30 }
# supports ISO duration, "human duration" as used in code
timeout: { minutes: 3 }
workspace: workspace-name
note

It is possible but certainly not recommended to skip the provider ID level.

If you do so, default will be used as provider ID.

  • catalogPath (optional): Default: /catalog-info.yaml. Path where to look for catalog-info.yaml files. When started with /, it is an absolute path from the repo root. Otherwise, it matches the file at the repo root and in any folder. In the path, * matches any characters, including /, and ? matches one character.
  • filters (optional):
    • projectKey (optional): Regular expression used to filter results based on the project key.
    • repoSlug (optional): Regular expression used to filter results based on the repo slug.
  • schedule:
    • frequency: How often you want the task to run. The system does its best to avoid overlapping invocations.
    • timeout: The maximum amount of time that a single task invocation can take.
    • initialDelay (optional): The amount of time that should pass before the first invocation happens.
    • scope (optional): 'global' or 'local'. Sets the scope of concurrency control.
  • workspace: Name of your organization account/workspace. If you want to add multiple workspaces, you need to add one provider config each.