Executing a workflow

This page shows you how to execute a workflow in the Google Cloud Console,using the gcloud command-line tool, or by sending a request to the Workflows REST API. Executing a workflow runs the current workflow definition associated with the workflow.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

Executing a workflow

Console

  1. To execute a workflow, go to the Workflows page in the Google Cloud Console:
    Go to the Workflows page

  2. On the Workflows page in the console, select the workflow you want to run to be taken to its details page.

  3. On the Workflow details page, select Execute.

  4. On the Execute workflow page, you can enter optional runtime arguments to pass to your workflow before execution. Arguments must be in JSON format; for example, {"animal":"cat"}. If your workflow doesn't use runtime arguments, leave this blank.

  5. Select Execute.

  6. View the workflow's results in the Output pane:

    Workflows quickstart output

gcloud

  1. Open a terminal.

  2. Find the name of the workflow you want to execute. If you don't know the workflow's name, you can enter the following command to list all your workflows:

    gcloud workflows list
    
  3. Execute the workflow by entering the following command:

    gcloud workflows run WORKFLOW_NAME [--data=DATA]
    

    Replace the following:

    • WORKFLOW_NAME: The name of the workflow.

    • DATA: Optional. Runtime arguments for your workflow in JSON format.

    The command returns the results of the execution attempt. The output is similar to the following:

    argument: 'null'
    endTime: '2020-06-23T16:21:35.266171131Z'
    name: projects/123456789012/locations/us-central1/workflows/myFirstWorkflow/executions/f72bc6d4-5ea0-4dfb-bb14-2dae82303120
    result: '["Tuesday","Tuesday Weld","Tuesday Night Music Club","Tuesday (ILoveMakonnen
      song)","Tuesdays with Morrie","Tuesday Group","Tuesday Knight","Tuesday (Burak Yeter
      song)","Tuesday Morning Quarterback","Tuesday Maybe"]'
    startTime: '2020-06-23T16:21:34.826993288Z'
    state: SUCCEEDED
    workflowVersionId: '1'
    

To execute a workflow without waiting for the execution attempt to finish, enter the following command:

gcloud workflows execute WORKFLOW_NAME [--data=DATA]

Replace the following:

  • WORKFLOW_NAME: The name of the workflow.

  • DATA: Optional. Runtime arguments for your workflow in JSON format.

This returns a workflows executions describe command with the unique ID of the workflow execution attempt. The output is similar to the following:

Created [f72bc6d4-5ea0-4dfb-bb14-2dae82303120].

To view the workflow status, you can use following command:
gcloud workflows executions describe f72bc6d4-5ea0-4dfb-bb14-2dae82303120 --workflow myWorkflow

To view the status of the execution, enter the command returned by the previous step. This returns data about the workflow execution, including the result if the execution succeeded. The output is similar to the following:

argument: 'null'
endTime: '2020-06-23T16:21:35.266171131Z'
name: projects/123456789012/locations/us-central1/workflows/myFirstWorkflow/executions/f72bc6d4-5ea0-4dfb-bb14-2dae82303120
result: '["Tuesday","Tuesday Weld","Tuesday Night Music Club","Tuesday (ILoveMakonnen
   song)","Tuesdays with Morrie","Tuesday Group","Tuesday Knight","Tuesday (Burak Yeter
   song)","Tuesday Morning Quarterback","Tuesday Maybe"]'
startTime: '2020-06-23T16:21:34.826993288Z'
state: SUCCEEDED
workflowVersionId: '1'

Checking the status of long running executions

There are several commands to help you check the status of a workflow execution.

  • To retrieve a list of a workflow's execution attempts and their IDs, enter the following command:

    gcloud workflows executions list WORKFLOW_NAME
    

    Replace WORKFLOW_NAME with the name of the workflow.

  • To check the status of an execution attempt and wait for the attempt to finish, enter the following command:

    gcloud workflows executions wait EXECUTION_ID
    

    Replace EXECUTION_ID with the execution attempt's ID.

    The command waits for the execution attempt to finish and then returns the results.

  • To check the status of the last execution attempt, enter the following command:

    gcloud workflows executions wait-last
    

    If you made a previous execution attempt in the same gcloud session, the command waits for the prior execution attempt to finish and then returns the results. If no previous attempt exists, gcloud returns the following error:

    ERROR: (gcloud.workflows.executions.wait-last) [NOT FOUND] There are no cached executions available.
    
  • To get the status of the last completed execution, enter the following command:

    gcloud workflows executions describe-last
    

    If you made a previous execution attempt in the same gcloud session, the command returns the results of the last completed execution. If no previous attempt exists, gcloud returns the following error:

    ERROR: (gcloud.beta.workflows.executions.describe-last) [NOT FOUND] There are no cached executions available.
    

REST API

  1. Open a terminal.

  2. Find the name of the workflow you want to execute. If you don't know the workflow's name, you can enter the following command to list all your workflows:

    gcloud workflows list
    
  3. To authenticate, you will need a service account with sufficient privileges to execute the workflow. For more information on using a service account to authenticate from the command line, see Getting started with authentication.

  4. Enter the following command to execute the workflow, modifying the variables as necessary:

    curl \
    --request POST \
    --header "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    --header 'Content-Type: application/json' \
    "https://workflowexecutions.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/workflows/WORKFLOW_NAME/executions"
    

    If the workflow you are executing takes arguments, add the data flag. The value of data is a JSON formatted string with an argument whose value is one or more escaped parameter-value pairs. For example:

    --data '{"argument":"{\"PARAMETER\":\"VALUE\"}"}'
    

If a workflow accesses other Google Cloud resources, make sure it is associated with a service account that has the correct permissions to do so. To learn what service account is associated with an existing workflow, see Verifying a workflow's associated service account.

What's next