This page shows you how to use jumps or for loops to control the order in which your workflow's steps run. Basic jumps allow you to define which step the workflow runs next. Conditional jumps build on basic jumps, allowing you to use conditional expressions to control the order of execution through a workflow. For example, you can run certain steps only when a variable or response from another workflow step meets specific criteria.
The examples on this page use a sample API that returns the day of the week.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
- You should already have an existing workflow where you want to change the order of execution. To learn how to create and deploy a workflow, see Create and update a workflow.
Use jumps to change execution order
By default, all workflows are ordered lists where every step runs in the order you define in the workflow's source code. You can choose to override this default ordering by using jumps.
Basic jumps
You can specify which step to run next in a workflow by using basic jumps.
Console
Open the Workflows page in the Google Cloud console:
Go to WorkflowsSelect the name of the workflow where you want to change the order of execution of the existing steps.
On the Edit workflow page, select Next to go to the workflow editor.
Add the
nextfield at the end of a step to tell the workflow to jump to a particular step:YAML
- step_a: ... next: STEP_NAME_TO_JUMP_TO - step_b: ... - next_step: ...
JSON
[ { "step_a": { ... "next": "STEP_NAME_TO_JUMP_TO" } } { "step_b": { ... } } { "next_step": { ... } } ]
Replace
STEP_NAME_TO_JUMP_TOwith the name of the step you want the workflow to execute next. For example,next_step.Select Deploy.
gcloud
Open your workflow's definition file in the text editor of your choice.
Add the
nextfield at the end of a step to tell the workflow to jump to a particular step:YAML
- step_a: ... next: STEP_NAME_TO_JUMP_TO - step_b: ... - next_step: ...
JSON
[ { "step_a": { ... "next": "STEP_NAME_TO_JUMP_TO" } } { "step_b": { ... } } { "next_step": { ... } } ]
Replace
STEP_NAME_TO_JUMP_TOwith the name of the step you want the workflow to execute next. For example,next_step.Save the workflow file.
To deploy the workflow, enter the following command:
gcloud workflows deploy WORKFLOW_NAME \ --source=WORKFLOW_FILE.YAML
Replace the following:
WORKFLOW_NAME: required. The name of your workflow.WORKFLOW_FILE.YAML: required. The source file for the workflow.
Example
For example, the following workflow has its steps out of order:
YAML
- get_time: call: http.get args: url: https://us-central1-workflowsample.cloudfunctions.net/datetime result: currentTime - return_daylight_savings_bool: return: ${daylightSavings} - get_daylight_savings_bool: assign: - daylightSavings: ${currentTime.body.isDayLightSavingsTime}
JSON
[ { "get_time": { "call": "http.get", "args": { "url": "https://us-central1-workflowsample.cloudfunctions.net/datetime" }, "result": "currentTime" } }, { "return_daylight_savings_bool": { "return": "${daylightSavings}" } }, { "get_daylight_savings_bool": { "assign": [ { "daylightSavings": "${currentTime.body.isDayLightSavingsTime}" } ] } }