Hi, I'm trying to export steps from a bitbucket-pipelines.yml to another repositories so I can reuse them. Here is the approach I've been trying, but hasn't been able to use the anchor tags correctly.
Source pipeline (share-template)
export: true
definitions:
pipelines:
share-step-build:
- step: &build_docker_image
name: 'Build Docker image'
script:
- echo "Build docker image step"
share-step-push:
- step: &push_into_ecr
name: 'Push Into ECR'
script:
- echo "Push into ECR step"
Import pipeline
definitions:
steps:
- step: &build_docker_image
import: share-template:main:share-step-build
- step: &push_into_ecr
import: share-template:main:share-step-push
pipelines:
branches:
main:
- parallel:
steps:
- step:
<<: *build_docker_image
- step:
<<: *push_into_ecr
When I try this approach I get the following error:
No commands or pipes defined for the step at [pipelines > branches > main > 0 > parallel > steps > 0 > step]. Check that you have defined a valid "script" section.
What would it be the correct way to import these steps, so i can reuse them in my second pipeline using anchors and tags?
Hi Juan Sebastian,
It is not possible at the moment to reuse specific steps only with shared pipelines, you can only share a whole pipeline.
In the Source pipeline (share-template) you in your post, you have some definitions for shared pipelines that look correct. Then, in the Import pipeline, you are trying to import a whole pipeline into a specific step, which is why you get this error. Shared pipelines can only be imported under another pipeline, not under a step. E.g. like the following:
pipelines:
branches:
main:
import: share-template:main:share-step-build
In the above example, the pipeline share-step-build is imported under the pipeline of the main branch.
We have a feature request for the ability to share individual steps:
I suggest adding your vote to that feature request (by selecting the Vote for this issue link) as the number of votes helps our product managers better understand the demand for features. You are more than welcome to leave feedback, and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to be notified via email on updates.
Implementation of features is done as per our policy here and any updates will be posted in the feature request.
In the meantime, you could look into using dynamic pipelines instead for sharing a step across pipelines. This is the documentation for dynamic pipelines:
One of my colleagues has published a community article on how to share a step across pipelines with dynamic pipelines:
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.