Day #10 with Cloud Workflows: accessing built-in environment variables

Guillaume Laforge
Google Cloud - Community
1 min readDec 17, 2020

Google Cloud Workflows offers a few built-in environment variables that are accessible from your workflow executions.

There are currently 5 environment variables that are defined:

  • GOOGLE_CLOUD_PROJECT_NUMBER : The workflow project’s number.
  • GOOGLE_CLOUD_PROJECT_ID : The workflow project’s identifier.
  • GOOGLE_CLOUD_LOCATION : The workflow’s location.
  • GOOGLE_CLOUD_WORKFLOW_ID : The workflow’s identifier.
  • GOOGLE_CLOUD_WORKFLOW_REVISION_ID : The workflow’s revision identifier.

Let’s see how to access them from our workflow definition:

$ gcloud beta workflows deploy w09-new-workflow-from-cli \
--source=w09-hello-from-gcloud.yaml \
--service-account=workflow-sa@workflows-days.iam.gserviceaccount.com

We use the built-in sys.get_env() function to access those variables. We’ll revisit the various existing built-in functions in later episodes.

Then when you execute this workflow, you’ll get an output like this:

“workflows-days 783331365595 europe-west4 w10-builtin-env-vars 000001–3af”

There’s one variable I’d like to see added to this list, that would be the current execution ID. That could potentially be useful for identifying a particular execution, when looking in the logs, to reason about potential failure, or for auditing purposes.

Originally published at http://glaforge.appspot.com.

--

--

Guillaume Laforge
Google Cloud - Community

Developer Advocate for Google Cloud, Apache Groovy programming language co-founder, Java Champion