10

Lets suppose I've this

a: "ABC"
b: *a

I want b to have the same content than a, keep in mind that a is an string, not an array.

is this possible?

Arnold Roa
  • 7,335
  • 5
  • 50
  • 69
  • YAML is just a data format, but having said that, you can always use a query format like JsonPath or http://yaql.readthedocs.io/en/latest/getting_started.html to refer to another property or even an external value like an ENV or a property from a properties file. I've seen stuff like that in Azure Container Instances JSON. – Novaterata Feb 23 '18 at 03:42
  • Possible duplicate of [how to reference a YAML "setting" from elsewhere in the same YAML file?](https://stackoverflow.com/questions/2063616/how-to-reference-a-yaml-setting-from-elsewhere-in-the-same-yaml-file) – Novaterata Feb 23 '18 at 03:44
  • 1
    Possible duplicate, yes, but this question is more clearly trying to reuse a single string. I was glad to find it. – DylanReile May 15 '19 at 20:38

2 Answers2

18

Yes, that's called an alias. You make an Anchor with &anchorname and refer to it with *anchorname

a: &a "ABC"
b: *a
tinita
  • 3,987
  • 1
  • 21
  • 23
6

You can also use an array to define many aliases which is quite succinct.

aliases:
  - &foo "foo"
  - &bar "bar"
test1: *foo
test2: *bar
Paul Sturgess
  • 3,254
  • 2
  • 23
  • 22