This quickstart shows you how to execute a workflow and view the execution results using the Cloud Client Libraries.
For more information about installing the Cloud Client Libraries and setting up your development environment, see the Workflows client libraries overview.
You can complete the following steps by using the Google Cloud CLI in either your terminal or Cloud Shell.
Security constraints defined by your organization might prevent you from completing the following steps. For troubleshooting information, see Develop applications in a constrained Google Cloud environment.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initCreate or select a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace PROJECT_ID with a name for the Google Cloud project you are creating.
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace PROJECT_ID with your Google Cloud project name.
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Verify that billing is enabled for your Google Cloud project.
Enable the Workflows API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which contains the
serviceusage.services.enable permission. Learn how to grant
roles.
gcloud services enable workflows.googleapis.com
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initCreate or select a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace PROJECT_ID with a name for the Google Cloud project you are creating.
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace PROJECT_ID with your Google Cloud project name.
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Verify that billing is enabled for your Google Cloud project.
Enable the Workflows API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which contains the
serviceusage.services.enable permission. Learn how to grant
roles.
gcloud services enable workflows.googleapis.com
Set up authentication:
roles/iam.serviceAccountCreator) and the Project IAM Admin role
(roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
Create the service account:
gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
Replace SERVICE_ACCOUNT_NAME with a name for the service account.
Grant the roles/logging.logWriter IAM
role to the service account:
gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=roles/logging.logWriter
Replace the following:
SERVICE_ACCOUNT_NAME: the name of the service accountPROJECT_ID: the project ID where you created the service accountTo learn more about service account roles and permissions, see Grant a workflow permission to access Google Cloud resources.
To get the permissions that you need to complete this quickstart, ask your administrator to grant you the following IAM roles on your project:
roles/iam.serviceAccountUser)roles/workflows.admin)For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
After defining a workflow, you deploy it to make it available for execution. The deploy step also validates that the source file can be executed.
The following workflow sends a request to a public API and then returns the API's response.
Create a text file with the filename myFirstWorkflow.yaml with
the following content:
After creating the workflow, you can deploy it, but don't execute the workflow:
gcloud workflows deploy myFirstWorkflow \ --source=myFirstWorkflow.yaml \ --service-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \ --location=CLOUD_REGION
Replace CLOUD_REGION with a
supported location for the workflow. The default
region used in the code samples is us-central1.
You can clone the sample code from GitHub.
Clone the sample app repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/dotnet-docs-samples.git
Alternatively, you can download the sample as a zip file and extract it.
git clone https://github.com/GoogleCloudPlatform/golang-samples.git
Alternatively, you can download the sample as a zip file and extract it.
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
Alternatively, you can download the sample as a zip file and extract it.
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
Alternatively, you can download the sample as a zip file and extract it.
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
Alternatively, you can download the sample as a zip file and extract it.
Change to the directory that contains the Workflows sample code:
cd dotnet-docs-samples/workflows/api/Workflow.Samples/
cd golang-samples/workflows/executions/
cd java-docs-samples/workflows/cloud-client/
cd nodejs-docs-samples/workflows/quickstart/
cd python-docs-samples/workflows/cloud-client/
Take a look at the sample code. Each sample app does the following:
You can run the sample code and execute your workflow. Executing a workflow runs the deployed workflow definition associated with the workflow.
To run the sample, first install dependencies:
dotnet restore
go mod download
mvn compile
npm install -D tsx
pip3 install -r requirements.txt
Run the script:
GOOGLE_CLOUD_PROJECT=PROJECT_ID LOCATION=CLOUD_REGION WORKFLOW=WORKFLOW_NAME dotnet run
GOOGLE_CLOUD_PROJECT=PROJECT_ID LOCATION=CLOUD_REGION WORKFLOW=WORKFLOW_NAME go run .
GOOGLE_CLOUD_PROJECT=PROJECT_ID LOCATION=CLOUD_REGION WORKFLOW=WORKFLOW_NAME mvn compile exec:java -Dexec.mainClass=com.example.workflows.WorkflowsQuickstart
npx tsx index.js
GOOGLE_CLOUD_PROJECT=PROJECT_ID LOCATION=CLOUD_REGION WORKFLOW=WORKFLOW_NAME python3 main.py
Replace the following:
PROJECT_ID: your Google Cloud project nameCLOUD_REGION: the location of your workflow (default: us-central1)WORKFLOW_NAME: your workflow name (default: myFirstWorkflow)The output is similar to the following:
Execution finished with state: SUCCEEDED
Execution results: ["Thursday","Thursday Night Football","Thursday (band)","Thursday Island","Thursday (album)","Thursday Next","Thursday at the Square","Thursday's Child (David Bowie song)","Thursday Afternoon","Thursday (film)"]
Depending on the client library language, you can also pass a runtime argument in an execution request. For example:
// Execute workflow
try {
const createExecutionRes = await client.createExecution({
parent: client.workflowPath(projectId, location, workflow),
execution: {
argument: JSON.stringify({"searchTerm": "Friday"})
}
});
const executionName = createExecutionRes[0].name;
For more information about passing runtime arguments, see Pass runtime arguments in an execution request.
To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the Google Cloud project with the resources.
Delete the workflow you created:
gcloud workflows delete myFirstWorkflow
When asked if you want to continue, enter y.
The workflow is deleted.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-09 UTC.