Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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?

Hi.

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

definitions:
caches:
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.
caches:
- terraform-plugins
- terraform-local-plugins
- terraform-modules
script:
- 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

branches:
master:
-
step:
<<: *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." (https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/), 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 (https://github.com/yaml/yaml/issues/35) and no you can't.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
Community showcase
Published in Bitbucket

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

478 views 5 4
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