Workflows
Last updated
Last updated
Workflows allow users to define simple, CI-like sequences of Garden commands and script steps, that can be run from a command line, in CI pipelines or directly triggered from PRs or branches using Garden Cloud.
Custom shell scripts can be used for preparation ahead of running Garden commands, handling outputs from the commands, and more.
A sequence of commands executed in a workflow is also generally more efficent than scripting successive runs of Garden CLI commands, since state is cached between the commands, and there is no startup delay between the commands.
As of Garden 0.13, the CLI command to run a Workflow is garden workflow
instead of garden run workflow
.
Workflows are defined with a separate kind of configuration file, with a list of steps:
We suggest making a workflows.garden.yml
next to your project configuration in your project root. You can also place your workflow definitions in your project root project.garden.yml
/garden.yml
file (with a ---
separator after the project configuration).
Each step in your workflow can either trigger Garden commands, or run custom scripts. The steps are executed in succession. If a step fails, the remainder of the workflow is aborted.
You can run a workflow by running garden workflow <name>
, or have it via Garden Cloud.
A simple command step looks like this:
You can also provide arguments to commands, and even template them:
A script step looks something like this:
Scripts can also be templated:
To explicitly provide environment variables to the steps of a workflow, you can use the workflow.envVars
field:
Workflow-level environment variables like this can be useful e.g. for providing templated values (such as secrets or project variables) to several script steps, or to initialize providers in the context of a CI system.
Note that workflow-level environment variables apply to all steps of a workflow (both command and script steps).
skip
and when
optionsBy default, a workflow step is run if all previous steps have been run without errors. Sometimes, it can be useful to override this default behavior with the skip
and when
fields on workflow steps.
The skip
field is a boolean. If its value is true
, the step will be skipped, and the next step will be run as if the skipped step succeeded.
The when
field can be used with the following values:
onSuccess
(default): This step will be run if all preceding steps succeeded or were skipped.
onError
: This step will be run if a preceding step failed, or if its preceding step has when: onError
. If the next step has when: onError
, it will also be run. Otherwise, all subsequent steps are ignored. See below for more.
always
: The step will always be run, regardless of whether any previous steps have failed.
never
: The step will always be ignored, even if all previous steps succeeded. Note: Ignored steps don't show up in the command logs.
The simplest usage pattern for onError
steps is to place them at the end of your workflow (which ensures that they're run if any step in your workflow fails):
A more advanced use case is to use onError
steps to set up "error handling checkpoints" in your workflow.
For example, if the first step (run my-task
) fails in this workflow:
then the first two onError
steps will be run, and all other steps will be skipped (except for the last one, since it has when: always
). This can be useful for rollback operations that are relevant only at certain points in the workflow.
You can also template the values of skip
and when
for even more flexibility. For example:
Workflow steps can reference outputs from previous steps, using template strings. This is particularly useful when feeding command outputs to custom scripts, e.g. for custom publishing flows, handling artifacts and whatever else you can think of.
For example, to retrieve a module version after a build:
You can also set a name
on a step, to make it easier to reference:
Garden Cloud can monitor your project repository for updates, and trigger workflows automatically on e.g. PR and branch updates.
For example, here's how you'd trigger a workflow for PRs made from any feature/*
branch:
Unlike actions, workflows stand outside of the Stack Graph. They cannot currently depend on each other, and nothing in the Stack Graph can reference or otherwise depend on workflows.
Here we use secrets (which are a Garden Enterprise feature) for the auth key, but you can replace those template keys with corresponding ${var.*}
or ${local.env.*}
keys as well.
Not all Garden commands can be run in workflows, and some option flags are not available. Please see the to see which commands are supported in workflows.
The available keys for templating can be found in the .
Note that skipped steps don't produce any outputs (see the section below for more). However, skipped steps are shown in the command log.
The schema of command outputs can be found in the . Every step also exports a log
key for the full command or script log.
For a full description of how to configure triggers, check out the .
Take a look at our for details on how to use templating in your configuration files.
Also check out for CLI usage examples, and some common day-to-day usage tips.