Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can you add to a pre-existing script element in the pipeline yaml file?


Using yaml anchors is a great way to deduplicate content in the bitbucket_pipelines.yml file.

My use case it that I want to use the same anchored step for the commit, pull_request, and master merge, with 1 extra command on the master merge.

I know I could put the whole lot into a shell script and do the work there, but that's not the question.

So take a file like ...

image      : devops/terraforming:tf-0.12.29-aws-2.0.36-jq-1.5-git-2.23.3

clone :
depth: 1

terraform-plugins: /root/.terraform.d/plugin-cache
terraform-local-plugins: .terraform/plugins
terraform-modules: .terraform/modules
steps :
step: &plan
name : Run Terraform init, validate, and plan.
- terraform-plugins
- terraform-local-plugins
- terraform-modules
- echo 'plugin_cache_dir="/root/.terraform.d/plugin-cache"' >> ~/.terraformrc
- mkdir -p /root/.terraform.d/plugin-cache
- terraform init -upgrade -backend-config key=$BACKEND_KEY_NAME.tfstate
- terraform validate
- export TF_VAR_current_datetime=$(TZ=UTC date "+%Y-%m-%dT%H:%M:%SZ")
- terraform plan -var-file terraform.tfvars -state=terraform.tfstate -out=terraform.tfplan

pipelines :
pull-requests :
'**' :
step: *plan

default :
step: *plan

<<: *plan
deployment: production
script :
- terraform apply -auto-approve terraform.tfplan

I know also I could have another step, but that would involve more processing time as a new container is spun up and I'd have to work out what to carry across from one step to the next.

The documentation for anchored steps says "You can use overrides with the characters '<<:' to add more values, or override existing ones." (, but before I start testing this, an I able to do this or am I doomed for failure before I start?

1 answer

1 accepted

0 votes
Answer accepted

And just read a debate about this sort of thing in the YAML ( and no you can't.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,793 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you