The workflows were previously defined using HCL (the syntax used in Terraform), which seems like it could have supported some of this better.
Honestly not sure why YAML is used so much. It either has stuff like this hacked in, or some templating structure, or both. Never the same between one CI tool and another, so you're always having to re-learn how to substitute an environment variable, or use some constructs provided by the tool itself.
And for any half-way complex pipeline, this YAML file will be a few thousand lines long, if not more, and basically impossible to follow.