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?
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.