Wiki
Clone wikisnakeyaml / Variable substitution
Your configuration options can contain environment variables. SnakeYAML implements Variable substitution similar to how it works in docker-compose.
Only ${VARIABLE}
syntax is supported.
it is possible to provide inline default values using typical shell syntax (exactly as for docker-compose):
${VARIABLE:-default}
evaluates todefault
ifVARIABLE
is unset or empty in the environment.${VARIABLE-default}
evaluates todefault
only ifVARIABLE
is unset in the environment.${VARIABLE:?err}
exits with an error message containingerr
ifVARIABLE
is unset or empty in the environment.${VARIABLE?err}
exits with an error message containingerr
ifVARIABLE
is unset in the environment.
If variable is not set, the empty value is used. Except when it is explicitly instructed to fail.
Since SnakeYAML is no template engine, it does not substitute parts of scalar, only the whole scalar. For instance this stays as it is because template is just a part of the scalar:
environment: - DEBUG=${DEBUG} - "DIR=${DATA_DIR}"
environment: DEBUG: ${DEBUG} DIR: ${DATA_DIR}
An example of the implementation can be found in tests.
An an example with Lombok can also be found in tests.
Updated