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
name : Run Terraform init, validate, and plan.
- 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
- 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?
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...
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