Zeljko's Blog

TIL: Yaml Features

Created: 2023-03-06
Last Modified: 2025-01-29

After reading through the documentation for the GitLab CI I came across something called “anchors”. I was aware of a feature like this, but never bothered with it. Until today. The documentation referenced to the YAML entry at Learn X in Y minutes. I like this website and it’s useful. In my opinion it is nice for getting into a technology fairly fast or to check how a particular language feature is used (mostly because of syntax).

Until now, I treated YAML more or less like Python flavoured JSON. But seeing what (strange) things are possible with YAML makes me reconsider that. I am familiar with the | and > syntax to handle strings in YAML. But I was not aware, that I could have “complex” values as keys. Neither was I aware of the anchor and merge syntax. Or that YAML can provide type annotation. Or that YAML has sets.

When writing Kubernetes manifests (Helm Charts) or GitLab CI Pipelines never used them. They were simply not necessary. Mostly because Helm Charts already have templating and can become complex by themselves. But for a pipeline for example it could be nice. With an anchor and the merge syntax one could in one place set environment variables and reuse them this way. But GitLab CI offers something called inheritance which can do something similar. It’s clear it can do a lot more. I would like to try it out and then make an opinion on these language features.

Following the documentation on https://yaml.org/ I found https://matrix.yaml.info/. This website covers the differences throughout YAML parsers in different programming languages. To be honest I expected them to “work properly” and not fail on valid input. Still, it’s interesting and there is much more to say about YAML, but I wanted to keep it short. Thank you for reading.