Creating and updating a workflow

This page shows you how to create a workflow and update an existing workflow in the Google Cloud Console or using the gcloud command-line tool.

Before you begin

  1. 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.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  4. Enable the Workflows API.

    Enable the Workflows API
  5. Create a service account if you don't already have one, then grant it the roles necessary for managing workflows and creating logs.

    Console

    1. In the Cloud Console, go to the Service accounts page.

      Go to the Create Service Account page
    2. Select Create service account.
    3. In the Service account name field, enter a name.
    4. Click Create.
    5. From the Role list, select Logging >Logs Writer.

      Note: The Role field 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. If you are developing a production app, always grant the least permissive roles possible. For more information, see granting roles to service accounts. For a list of Workflows roles, see the Access control reference.
    6. Click Continue.
    7. Click Done.

    gcloud

    1. Create the service account. Replace [NAME] with a name for the service account.

      gcloud iam service-accounts create [NAME]
    2. 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:
      • [PROJECT_ID]: Your project's ID.
      • [NAME]: The name of the service account you just created.
      Note: The Role field authorizes your service account to access resources. To send logs to Cloud Logging, assign the roles/logging.logWriter role. If you are developing a production app, always grant the least permissive roles possible. For more information, see granting roles to service accounts. For a list of Workflows roles, see the Access control reference.

Creating a workflow

To create a workflow, we 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

  1. To create a new workflow, open the Workflows page in the Google Cloud Console:
    Go to the Workflows page

  2. Select Create.

  3. 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.

  4. Choose us-central1 for the region.

  5. Select the service account you want 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. To learn more about service accounts, see Creating and managing service accounts.

  6. Select Next.

  7. In the workflow editor, enter the definition for your workflow. You can find an example workflow on the Quickstart using the Cloud Console page.

  8. Select Deploy.

gcloud

  1. Make sure your workflow's source code is saved in a YAML or JSON file, such as MY_WORKFLOW.YAML or MY_WORKFLOW.JSON. You can find an example workflow on the Quickstart using the gcloud tool page.

  2. Open a terminal.

  3. Deploy the workflow by entering the following command:

    gcloud workflows deploy MY_WORKFLOW \
    --source=MY_WORKFLOW.YAML \
    [--service-account=MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM]
    

    Replace the following:

    • MY_WORKFLOW: The name of your workflow.

    • MY_WORKFLOW.YAML: The source file to use for the workflow.

    • 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. To learn more about service accounts, see Creating and managing service accounts.

Updating a workflow

You can update an existing workflow to change its source, description, labels, or its associated service account. Updating a workflow does not affect in progress executions. Only future executions of the workflow will use the updated configurations.

Console

  1. To update an existing workflow, open the Workflows page in the Google Cloud Console:
    Go to the Workflows page

  2. Select the name of the workflow you want to update.

  3. On the Edit workflow page, you can edit the description, update the service account the workflow uses for authentication, or add a label. You cannot edit the workflow's name.

  4. Select Next when finished with your initial updates.

  5. To edit the workflow's source, update the source code in the workflow editor.

  6. Select Deploy.

gcloud

  1. Locate the YAML or JSON file where your updated workflow source is saved, such as WORKFLOW_FILE.YAML or WORKFLOW_FILE.JSON.

  2. Open a terminal.

  3. 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
    
  4. You can update a workflow's source, associated service account, description, or labels:

    gcloud workflows deploy WORKFLOW_NAME \
    --source=WORKFLOW_FILE.YAML \
    [--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.

    • WORKFLOW_FILE.YAML: Required. The source file for the workflow.

    • MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM: Optional. The service account your workflow will use to access other Google Cloud services. To learn more about service accounts, see Creating and managing service accounts.

    • KEY=VALUE: Optional. Labels you want to add in KEY=VALUE pairs, in a comma-separated list if you add more than one.

    • 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, but the rest of the flags are optional.

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.

What's next