How can I set a value in YAML from another key e.g:
example.emails:
- [email protected]
- [email protected]
- [email protected]
swift:
to_email: example.emails
As we can see, the format is very simple. Each key is followed by a colon and then the value. We can also use quotation marks ( ' or " ) around the key-value pair if we want to include special characters or whitespace.
In YAML, you can only define variables with pipeline or action scope. Workspace and project variables need to be defined via the GUI.
The YAML above defines four keys - first_name , last_name , age_years , and home - with their four respective values. Values can be character strings, numeric (integer, floating point, or scientfic representation), Boolean ( true or false ), or more complex nested types (see below).
The key-value is YAML's basic building block. Every item in a YAML document is a member of at least one dictionary. The key is always a string. The value is a scalar so that it can be any datatype. So, as we've already seen, the value can be a string, a number, or another dictionary.
Accepted answer is wrong. It might have worked for the author for app specific reason but it is not supported by YAML specs. The correct way to reuse values in yaml is through something called anchors, like this
x1: &my_anchor
y: 'my val'
x2:
<<: *my_anchor
z: 3
In above, we mark the values in x1
using anchor my_anchor
. Then the special syntax <<: *my_anchor
tells YAML parser to insert children of the node (in this case y
) in the same level. So x2
will now have two children: y
and z
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With