How to set up a shared Bitbucket pipeline for the main branch

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

Pipelines configuration sharing is a Bitbucket Cloud Premium feature. Learn more about Bitbucket Premium

Bitbucket Cloud recently released the Pipelines YML sharing feature, as you can check the announcement post here.

The official documentation provides an example of using this feature with a custom trigger. This article aims to give a valuable example of how to use the feature to trigger builds automatically for a branch on both exporting and imported repositories.

Environment

Bitbucket Cloud Pipelines.

Solution

In the following example, we are creating a configuration to trigger builds on the repository's main branch.

The YML configuration to use on the exporting repo:

bitbucket-pipelines.yml

1 2 3 4 5 6 7 8 9 10 11 12 13 14 export: true image: atlassian/default-image:4 definitions: pipelines: share-pipeline-1: &share-pipeline-1 - step: name: 'hello world' script: - echo hello pipelines: branches: main: *share-pipeline-1

The YML configuration to use on the importing repo:

bitbucket-pipelines.yml

1 2 3 4 pipelines: branches: main: import: testing-pipelines:main:share-pipeline-1

The syntax for using the import flag is:

1 {repo-slug-of-exported-pipeline}:{branch/tag-to-import-from}:{pipeline-from-exported-file}

So, in this example, we are importing the "share-pipeline-1" step from the main branch of the "testing-pipelines" repository.

Updated on March 14, 2025

Still need help?

The Atlassian Community is here for you.