YAML Anchors and Alias
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.
note
Anchors and aliases are very useful for larger projects, as they reduce the visual clutter caused by extra lines.
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