To create a workflow, you use the Workflows syntax to define the steps you want and their order of execution. For more information about creating workflows, see Create and manage workflows.
For other functions available in addition to the core syntax, refer to the Standard library and Connectors references.
File structure
Workflow source files have the following characteristics:
- They contain only one main workflow.
- They might contain subworkflows.
They are either a valid YAML or JSON file.
Code samples are provided in both YAML and the equivalent JSON.
Search the syntax
You can search the Workflows syntax for its reserved words and other details. To see examples of the syntax in action, see the cheat sheet.
Reserved word | Description | Use with | See also | Examples |
---|---|---|---|---|
|
Pass arguments and their values when calling a function that accepts parameters. | call steps
|
call result |
|
|
Set the value of a variable. | — | — | |
|
Execute parallel branches concurrently and the steps in each branch sequentially. |
steps
|
parallel |
|
|
Terminate iteration of a for loop.
|
next in for loops
|
continue |
|
|
Run a function and return a result. | — | args result |
|
|
Provide an expression to control if a step is executed (the first condition to evaluate as true). | switch
|
— | |
|
Terminate the current iteration of a for loop and
continue with the next iteration.
|
next in for loops
|
break |
|
|
Stop a workflow's execution without returning a value. | next
|
— | |
|
Catch and handle errors thrown during a workflow execution. |
try
|
retry |
|
for |
Iterate over a sequence of numbers or through a collection of data, such as a list or map. | steps |
— | |
|
Define your main workflow. If a workflow
has a subworkflow, or to receive runtime arguments, there must be a
main block. |
Subworkflows | — | |
|
Define what step Workflows should execute next. | — | break continue |
|
|
Execute two or more steps concurrently. |
branches for loopssteps
|
— | |
|
Accept workflow execution arguments, or arguments passed to a subworkflow. | Subworkflows | main |
|
|
Raise custom errors. | — |
except retry try
|
|
|
Assign the result from a call to this variable. | call steps
|
args |
|
|
Define the retry behavior and the number of retry attempts. | try
|
— | |
|
Stop a workflow's execution and return a value or expression. | — | — | |
|
Nest a series of steps. |
branches for loopsSubworkflows try
|
main |
|
|
Allow the value of an expression to control the flow of a workflow's execution. | — | condition |
|
|
Define a list of steps to retry if an error is raised, or catch and handle the error. | — | except retry
|
Example: break
-FOR_LOOP_STEP_NAME_A : for: value:LOOP_VARIABLE_NAME_A in: ${LIST_EXPRESSION_A } # or simply in: LIST_DEFINITION steps: -STEP_NAME_A : next: continue -FOR_LOOP_STEP_NAME_B : for: value:LOOP_VARIABLE_NAME_B range: [${BEGIN_EXPRESSION }, ${END_EXPRESSION }] steps: -STEP_NAME_B : next: break
[ { "FOR_LOOP_STEP_NAME_A ": { "for": { "value": "LOOP_VARIABLE_NAME_A ", "in": "${LIST_EXPRESSION_A }", "steps": [ { "STEP_NAME_A ": { "next": "continue" } } ] } } }, { "FOR_LOOP_STEP_NAME_B ": { "for": { "value": "LOOP_VARIABLE_NAME_B ", "range": [ "${BEGIN_EXPRESSION }", "${END_EXPRESSION }" ], "steps": [ { "STEP_NAME_B ": { "next": "break" } } ] } } } ]
Example: condition
-STEP_NAME_A : switch: - condition: ${EXPRESSION_A } next:STEP_NAME_B - condition: ${EXPRESSION_B } next:STEP_NAME_C - condition: true next:STEP_NAME_C next:STEP_NAME_D
[ { "STEP_NAME_A ": { "switch": [ { "condition": "${EXPRESSION_A }", "next": "STEP_NAME_B " }, { "condition": "${EXPRESSION_B }", "next": "STEP_NAME_C " } { "condition": true, "next": "STEP_NAME_C " } ], "next": "STEP_NAME_D " } } ]
Example: continue
-FOR_LOOP_STEP_NAME_A : for: value:LOOP_VARIABLE_NAME_A in: ${LIST_EXPRESSION_A } # or simply in: LIST_DEFINITION steps: -STEP_NAME_A : next: continue -FOR_LOOP_STEP_NAME_B : for: value:LOOP_VARIABLE_NAME_B range: [${BEGIN_EXPRESSION }, ${END_EXPRESSION }] steps: -STEP_NAME_B : next: break
[ { "FOR_LOOP_STEP_NAME_A ": { "for": { "value": "LOOP_VARIABLE_NAME_A ", "in": "${LIST_EXPRESSION_A }", "steps": [ { "STEP_NAME_A ": { "next": "continue" } } ] } } }, { "FOR_LOOP_STEP_NAME_B ": { "for": { "value": "LOOP_VARIABLE_NAME_B ", "range": [ "${BEGIN_EXPRESSION }", "${END_EXPRESSION }" ], "steps": [ { "STEP_NAME_B ": { "next": "break" } } ] } } } ]
Example: for
-FOR_LOOP_STEP_NAME : for: value:LOOP_VARIABLE_NAME index:INDEX_VARIABLE_NAME in: ${LIST_EXPRESSION } steps: -STEP_NAME_A : ...
[ { "FOR_LOOP_STEP_NAME ": { "for": { "value": "LOOP_VARIABLE_NAME ", "index": "INDEX_VARIABLE_NAME ", "in": "${LIST_EXPRESSION }", "steps": [ { "STEP_NAME_A ": ... } ] } } } ]
Example: params
main: steps: -STEP_NAME : call:SUBWORKFLOW_NAME args:ARG_1 :VALUE_1 ARG_2 :VALUE_2 ... result:OUTPUT_VARIABLE SUBWORKFLOW_NAME : params: [PARAMETER_1 ,PARAMETER_2 ...] steps: - step_1: ...
{ "main": { "steps": [ { "STEP_NAME ": { "call": "SUBWORKFLOW_NAME ", "args": { "ARG_1 ": "VALUE_1 ", "ARG_2 ": "VALUE_2 " }, "result": "OUTPUT_VARIABLE " } } ] }, "SUBWORKFLOW_NAME ": { "params": ["PARAMETER_1 ,PARAMETER_2 "...], "steps": [ { "step_1": ... } ] } }
Example: retry
- step_name: try: steps: ... retry:RETRY_POLICY predicate:RETRY_PREDICATE max_retries:NUMBER_OF_RETRIES backoff: initial_delay:DELAY_SECONDS max_delay:MAX_DELAY_SECONDS multiplier:DELAY_MULTIPLIER
[ { "step_name": { "try": { "steps": [ ... ] }, "retry": "RETRY_POLICY " "predicate": "RETRY_PREDICATE ", "max_retries":NUMBER_OF_RETRIES , "backoff": { "initial_delay":DELAY_SECONDS , "max_delay":MAX_DELAY_SECONDS , "multiplier":DELAY_MULTIPLIER } } } ]
Example: steps
Example: switch
-STEP_NAME_A : switch: - condition: ${EXPRESSION_A } next:STEP_NAME_B - condition: ${EXPRESSION_B } next:STEP_NAME_C - condition: true next:STEP_NAME_C next:STEP_NAME_D
[ { "STEP_NAME_A ": { "switch": [ { "condition": "${EXPRESSION_A }", "next": "STEP_NAME_B " }, { "condition": "${EXPRESSION_B }", "next": "STEP_NAME_C " } { "condition": true, "next": "STEP_NAME_C " } ], "next": "STEP_NAME_D " } } ]
Example: stub
Using code samples
For all samples that communicate with other Google Cloud resources, your workflow must be associated with a service account that has sufficient privileges to access those resources. To learn more about granting roles to service accounts, see Manage access to projects, folders, and organizations. To learn how to change the service account associated with a workflow, see update a workflow. For more information about authentication, see Grant a workflow permission to access Google Cloud resources.
Some samples might require that you first enable a Google Cloud API. Learn more about listing services and enabling services.
See all Workflows code samples.
Notation key
Notation | Description |
---|---|
[] Square brackets |
Optional; if the brackets themselves must be typed, this is indicated |
{} Braces |
Required |
| Vertical bar |
Separator for mutually exclusive items; choose one |
... Ellipsis |
Items that can be repeated; or indicates an omission to improve clarity and shorten the length of the example |