Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

YAML anchors not working as documented

Cosimo Commisso
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 7, 2025

 

We make heavy use of YAML anchors in our bitbucket-pipelines.yml files. We have a simple step named build-test which builds the bundle and runs unit tests. We want a separate deployment value set depending on the branch. With the following configuration

definitions:

steps:
- step: &build-test
size: 2x
deployment: test # I want to be able to override this
max-time: 15
name: Build
caches:
- node
script:
- echo "do something"

pipelines:
branches:
master:
- step:
<<: *build-test
deployment: production
develop:
- step:
<<: *build-test
deployment: test


 

I get the following error

There is an error in your bitbucket-pipelines.yml at [pipelines > branches > develop > 1 > step > script > 0]. Missing or empty command string. Each item in this list should either be a single command string or a map defining a pipe invocation.

 

Im using this as a reference: https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/

 

This error is forcing me to define multiple steps which do the same thing.

1 answer

0 votes
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 8, 2025

Hi Cosimo,

The issue you're seeing happens because YAML anchors and aliases in Bitbucket Pipelines can't override individual child nodes within a section. Instead, they replace the entire section. In your case, when you attempt to override the deployment value, it causes the script section to be overridden/removed.

To resolve this:

  • You need to ensure that the script section remains intact while overriding the deployment value.
  • You can do so by leaving the deployment field empty in your step definition, and instead continue to define it in your branches definition

Please try the following config and let me know how it goes:

definitions:
    steps:
       - step: &build-test
             size: 2x
             max-time: 15
             name: Build
             caches:
                 - node
             script:
                 - echo "do something"

pipelines:
   branches:
      master:
           - step:
                 <<: *build-test
                 deployment: production
      develop:
           - step:
                 <<: *build-test
                 deployment: test

Cheers!

- Ben (Bitbucket Cloud Support)

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events