Overriding A Task Variable From Within A Task #731
-
This may be a silly question, but I can't seem to glean the answer from the docs and would greatly appreciate the clarity. I find myself not understanding how to programmatically update a Task variable from within a Task. This results in scenarios where I have to cast the variable to an ordinary bash variable. Is there a right way to do this? Given a root Task variable of:
Below is an example of me having to introduce a new local bash variable.
Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Vars cannot be updated per se, they can only be overwritten. Unfortunately, the way vars currently work is that you don't actually get access to the value as it is declared in a higher scope, if you declare a var in a child scope with the same name. The recommended approach is to declare a new var (different name) and then reference the global var. Here's an example: vars:
PARAMETER_NAME: "/{{.SYSTEM_NAME}}/${TERRAFORM_VARIABLE}"
tasks:
example:
vars:
DERIVED_PARAMETER: |
{{if (eq .TERRAFORM_VARIABLE "")}}{{.OTHER_PARAMETER_NAME}}{{else}}{{.PARAMETER_NAME}}{{end}}
cmds:
- echo '{{.DERIVED_PARAMETER}}' |
Beta Was this translation helpful? Give feedback.
Vars cannot be updated per se, they can only be overwritten. Unfortunately, the way vars currently work is that you don't actually get access to the value as it is declared in a higher scope, if you declare a var in a child scope with the same name.
The recommended approach is to declare a new var (different name) and then reference the global var.
Here's an example: