How to set up a shared Bitbucket pipeline for the main branch.
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Pipelines configuration sharing is a Bitbucket Cloud Premium feature. Learn more about Bitbucket Premium
Summary
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:
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:
pipelines:
branches:
main:
import: testing-pipelines:main:share-pipeline-1
The syntax for using the import flag is:
{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.