This page shows you how to create and manage workflows in the Google Cloud console, or by using the Google Cloud CLI in either your terminal or Cloud Shell. You can also manage workflows through the Workflows API.
Before you begin
Some of the steps in this document might not work correctly if your organization applies constraints to your Google Cloud environment. In that case, you might not be able to complete tasks like creating public IP addresses or service account keys. If you make a request that returns an error about constraints, see how to Develop applications in a constrained Google Cloud environment.
Console
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
Enable the Workflows API.
gcloud
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
Enable the Workflows API.
gcloud services enable workflows.googleapis.com
API
To manage workflows using the Workflows API, we recommend
that you use the Google-provided
client libraries to call the
workflows.googleapis.com
service. For more information, see
Workflows API.
Create a service account
Workflows uses service accounts to give workflows access to Google Cloud resources. Create a service account if you don't already have one; then grant it the roles necessary for managing workflows and creating logs. If you don't specify a service account during the workflow's creation, the workflow uses the default Compute Engine service account for its identity. Learn more about deploying a workflow with a service account.
Note that to create a resource and attach a service account, you need permissions to create that resource and to impersonate the service account that you will attach to the resource. For more information, see Service account permissions.
Console
In the Google Cloud console, go to the Service Accounts page.
Select a project and then click Create service account.
In the Service account name field, enter a name.
The name must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. After you create a service account, you cannot change its name.
Click Create and continue.
Click Select a role.
Select the following roles, clicking Add another role as required:
- To create, update, and execute workflows, select Workflows > Workflows Editor.
- To send logs to Cloud Logging, select Logging > Logs Writer.
Click Done to finish creating the service account.
gcloud
Create the service account.
gcloud iam service-accounts create NAME
Grant permissions to the service account by assigning a role.
gcloud projects add-iam-policy-binding PROJECT_ID \ --member "serviceAccount:NAME@PROJECT_ID.iam.gserviceaccount.com" \ --role "roles/logging.logWriter"
Replace the following:
NAME
: the name of the service account. It must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. After you create a service account, you cannot change its name.PROJECT_ID
: your project's ID.
The
--role
flag is used to authorizes your service account to access resources.- To create, update, and execute workflows, assign the
roles/workflows.editor
role. - To send logs to Cloud Logging, assign the
roles/logging.logWriter
role.
Create a workflow
A workflow definition is made up of a series of steps described using the Workflows syntax, which can be written in either YAML or JSON format. After creating a workflow, you deploy it to make it available for execution. The deploy step also validates that the source file can be executed. It fails if the source file doesn't contain a valid workflow definition.
Console
In the Google Cloud console, go to the Workflows page.
Click
Create.Enter a name for the new workflow, such as
myFirstWorkflow
. The name can contain letters, numbers, underscores, and hyphens. It must start with a letter and end with a number or letter.In the Region list, select an appropriate region; for example, us-central1.
In the Service account list, select a service account for your workflow to use for authentication with other Google Cloud services. We strongly recommend using a service account with the least privileges necessary to access the required resources. For more information, in this document, see Create a service account.
We strongly recommend using a service account with the least privileges necessary to access the required resources.
Optionally, do any of the following:
Add a label: labels are key-value pairs that help you organize your Google Cloud instances. For more information, see Create and manage labels.
Schedule your workflow: select Add new trigger > Cloud Scheduler. For more information, see Schedule a workflow using Cloud Scheduler.
Trigger your workflow through an event or Pub/Sub message: select Add new trigger > Eventarc. For more information, see Trigger a workflow with events or Pub/Sub messages.
Click Next.
In the workflow editor, enter the definition for your workflow. See an example workflow.
Click Deploy.
gcloud
Make sure your workflow's source code is saved in a YAML or JSON file, such as
MY_WORKFLOW.YAML
orMY_WORKFLOW.JSON
. See an example workflow.Open a terminal.
Deploy the workflow by entering the following command:
gcloud workflows deploy MY_WORKFLOW \ --source=YAML_OR_JSON_SOURCE_FILE \ --service-account=MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM
Replace the following:
MY_WORKFLOW
: the name of your workflow.YAML_OR_JSON_SOURCE_FILE
: the source file to use for the workflow. For example:myFirstWorkflow.yaml
.MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM
: optional. The service account your workflow will use to access other Google Cloud services. We strongly recommend using a service account with the least privileges necessary to access the required resources. If left blank, the default service account is used. For more information, in this document, see Create a service account.
API
Call the
projects.locations.workflows.create
method and use the workflowId
parameter to specify an ID for the workflow.
List workflows
You can list workflows or use filters to retrieve a specific workflow.
Console
In the Google Cloud console, go to the Workflows page.
This page lists your workflows in all locations, and includes details such as names, regions, latest revisions, and more.
To filter your workflows:
- Click Filter or the Filter workflows field.
- In the Properties list, select an option to filter the workflows by.
You can select a single property or use the logical operator OR
to add
more properties.
To sort your workflows, beside any supported column heading, click
Sort.gcloud
List workflows using the
gcloud workflows list
command:
gcloud workflows list --location=WORKFLOW_NAME
Replace LOCATION
with the ID or fully qualified
identifier for the location of your workflows
This command lists your workflows in the specified location, and includes
details such as a workflow's NAME
, STATE
, REVISION_ID
, and
UPDATE_TIME
.
API
Call the projects.locations.workflows.list method to list workflows in a given project and location. Or, call the projects.locations.workflows.get method to retrieve the details of a single workflow.
Update a workflow
You can update an existing workflow to change its source, description, labels, triggers, or its associated service account. Updating a workflow does not affect in-progress executions. Only future executions of the workflow will use the updated configuration.
Console
In the Google Cloud console, go to the Workflows page.
Click the name of the workflow you want to update. Note that you can't change the workflow's name.
The Workflows details page appears.
You can edit the workflow in the following ways:
To edit the source:
- Click the Source tab.
- Click Edit.
- To save your changes, click Save. The updated workflow is deployed.
To edit the description, update the service account the workflow uses for authentication, or add or update a label:
- Click the Details tab.
- Click the appropriate .
- To save your changes, click Save. The updated workflow is deployed.
To edit the previous fields at the same time, or add or update a trigger:
- Click Edit.
- To edit the source, click Next.
- To save your changes and deploy the updated workflow, click Deploy.
If you want to update the roles for your service account, click the Permissions tab.
Principals are users, groups, domains, or service accounts. To update an existing principal:
- Find a row containing the principal.
- Click Edit principal in that row.
- Click Add another role or click Delete role.
If you are adding a role, in the Select a role list, select an appropriate role.
To add another role, click Add another role.
Click Save.
gcloud
Open a terminal.
Find the name of the workflow you want to update. If you don't know the workflow's name, you can enter the following command to list all your workflows:
gcloud workflows list
Locate the YAML or JSON file where your workflow source is saved, such as
WORKFLOW_NAME.YAML
orWORKFLOW_NAME.JSON
.You can update a workflow's source, associated service account, description, or labels using the
gcloud workflows deploy
command:gcloud workflows deploy WORKFLOW_NAME \ --source=YAML_OR_JSON_SOURCE_FILE \ --service-account=MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM \ --labels=KEY=VALUE... \ --description='WORKFLOW_DESCRIPTION'
Replace the following:
WORKFLOW_NAME
: required. The name of your workflow.YAML_OR_JSON_SOURCE_FILE
: required. The source file for the workflow in either YAML or JSON format. For example:myFirstWorkflow.yaml
.MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM
: optional. The service account your workflow will use to access other Google Cloud services. If you want to update the roles for your service account, see Grant a workflow permission to access Google Cloud resources and Manage access to projects, folders, and organizations.KEY=VALUE
: optional.KEY=VALUE
pairs of labels, in a comma-separated list if you add more than one. Labels help you organize your Google Cloud instances. For more information, see Create and manage labels.WORKFLOW_DESCRIPTION
: optional. The description you want to give your workflow.
You must specify the name of the workflow you want to update and its source; however, the rest of the flags are optional.
API
Call the projects.locations.workflows.patch method to update an existing workflow.
Each time you update a workflow, its versionID
is updated. The versionID
consists of two parts, separated by a hyphen:
A number, starting at one, that is incremented each time you update a workflow.
A random, three-character, alphanumeric string.
For example, 000002-d52
indicates a workflow that has been updated once.
000001-27f
indicates a workflow that is on its initial version.
Delete a workflow
You can delete an existing workflow. Deleting a workflow also deletes its executions and cancels any active executions for the workflow.
Console
In the Google Cloud console, go to the Workflows page.
Click the name of the workflow you want to delete and then click
Delete.At the prompt to confirm the deletion, enter the workflow name.
Click Confirm.
gcloud
Open a terminal.
Find the name of the workflow you want to delete. If you don't know the workflow's name, you can enter the following command to list all your workflows:
gcloud workflows list
Delete a workflow using the
gcloud workflows delete
command:gcloud workflows delete WORKFLOW_NAME
Replace
WORKFLOW_NAME
with the name of your workflow.
API
Call the projects.locations.workflows.delete method to delete a workflow with a specified name.