Context
When customizing the values to be passed down to helm
from helmfile
, there are scenarios where it is desirable to accept potentially different values, depending on whether these are present or not.
For example, to specify the tag value for a docker image, we could pick its final value based on different environment variables, as follows:
- If
COMMIT_SHA
is present, use it - Else, if
BRANCH_NAME
is set, use it - Finally, if none of the previous environment variables are set, use
latest
Implementation
Instead of using an if/else
condition, which could be cumbersome and may not work, we can leverage the coalesce
function, which will pick the first non-empty value from a given list.
tag: {{ coalesce (env "COMMIT_SHA") (env "BRANCH_NAME") "latest" }}