salmon-scientist-57815
01/14/2025, 1:18 PMmicroscopic-river-74022
01/14/2025, 1:18 PMmicroscopic-river-74022
01/14/2025, 1:19 PM$if
, $then
, and $else
keys to conditionally set values. This method is often clearer and easier to work with compared to using conditional template strings. Here's an example:
yaml
kind: Deploy
spec:
command:
$if: ${this.mode == "sync"}
$then: [npm, run, watch]
$else: [npm, start]
In this case, the command
is set conditionally based on the mode of the action. [Using-garden > Variables and templating > Template string overview > If/else conditional objects]()
2. Using multi-line if/else blocks in strings:
For more complex conditional logic, especially in multi-line strings, you can use if/else blocks. The syntax is:
${if <expression>}<content>[${else}]<alternative content>${endif}
Here's an example:
yaml
variables:
some-script: |
#!/bin/sh
echo "Hello, I'm a bash script!"
${if environment.name == "dev"}
echo "-> debug mode"
DEBUG=true
${else}
DEBUG=false
${endif}
This allows you to conditionally include or exclude entire blocks of content. [Using-garden > Variables and templating > Template string overview > Multi-line if/else blocks in strings]()
3. Using the skip
option in workflow steps:
If you're working with workflows, you can use the skip
option to conditionally skip entire steps. For example:
yaml
steps:
- skip: "${environment.name != 'prod'}"
microscopic-river-74022
01/14/2025, 1:19 PMsteps[].skip
]()
By using these methods, you can make various aspects of your Garden configuration conditional, including requirements, based on different variables or conditions in your project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
01/14/2025, 1:19 PM