Skip to content

YAML Anchors and Alias

Learn how YAML anchors (&) and aliases (*) reduce repetition by reusing complex data structures across your YAML files for cleaner, more maintainable configurations.

YAML Anchors and Alias

Anchors and aliases are YAML constructs that help reduce syntax repetition and extend existing data nodes.

YAML Anchors allow us to store and reuse data within our YAML file.

An anchor is denoted by the “&” indicator and it can be placed on an entity to mark a multi-line section.

An alias is denoted by the “*” symbol and it is used to call an anchor in the document.

Example

Below, the build-and-test anchor begins on line 3 and it is called by aliases on lines 13 and 15.

definitions: 
  steps:
    - step: &build-and-test
        name: Build and test
        script:
          - mvn package
        artifacts:
          - target/**

pipelines:
  branches:
    develop:
      - step: *build-and-test
    master:
      - step: *build-and-test
Navigation