Configure environment variables for worker pools

Preview — Cloud Run worker pools

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

This page describes how to configure environment variables for your Cloud Runworker pool.

Any configuration change leads to thecreation of a new revision. Subsequent revisions will also automatically getthis configuration setting unless you make explicit updates to change it.

Required roles

To get the permissions that you need to configure and deploy Cloud Run worker pools, ask your administrator to grant you the following IAM roles:

For a list of IAM roles and permissions that are associated withCloud Run, seeCloud Run IAM rolesandCloud Run IAM permissions.If your Cloud Run worker pool interfaces withGoogle Cloud APIs, such as Cloud Client Libraries, see theservice identity configuration guide.For more information about granting roles, seedeployment permissionsandmanage access.

Warning: If your Cloud Run worker pool usesservice identity to authenticate accessto Google Cloud APIs, never setGOOGLE_APPLICATION_CREDENTIALS as anenvironment variable on a Cloud Run worker pool. Alwaysconfigure auser-managed service account instead.

Set environment variables

You can set environment variables for a Cloud Run worker pool using theGoogle Cloud console, the Google Cloud CLI, YAML, or Terraform:

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. SelectWorker pools from the menu, and clickDeploy container toconfigure a new worker pool.If you are configuring an existing worker pool, click theworker pool, then clickEdit and deploy new revision.

  3. If you are configuring a new worker pool, fill out the initial workerpool page, then clickContainer(s), Volumes, Networking, Security to expand theworker pools configuration page.

  4. Click theContainer tab.

    image

    • In the Variables & Secrets tab, clickAdd Variable to add a new environment variable, then specify the name you want for the variable in theName andValue fields. For more information on how to set multiple environment variables or escape special characters, seeSet multiple environment variables.
  5. ClickCreate orDeploy.

gcloud

To specify environment variables while deploying your worker pool, use the--set-env-vars flag:

gcloud beta run worker-pools deployWORKER_POOL --imageIMAGE_URL --set-env-varsKEY1=VALUE1,KEY2=VALUE2

Replace the following:

  • WORKER_POOL: the name of your worker pool
  • KEY1=VALUE1,KEY2=VALUE2: the comma-separated list of variablenames and values
  • IMAGE_URL: a reference to the container image thatcontains the worker pool, such asus-docker.pkg.dev/cloudrun/container/worker-pool:latest

For more information on how to set multiple environment variables or escapespecial characters, seeSet multiple environment variables.

YAML

  1. If you are creating a new worker pool, skip this step.If you are updating an existing worker pool, download itsYAML configuration:

    gcloudbetarunworker-poolsdescribeWORKER_POOL--formatexport>workerpool.yaml
  2. The following example contains the YAML configuration:

    apiVersion:run.googleapis.com/v1kind:WorkerPoolmetadata:name:WORKER_POOLannotations:run.googleapis.com/launch-stage:BETAspec:template:spec:containers:-name:image:IMAGE_URLenv:-name:NAMEvalue:VALUE-name:NAME2value:VALUE2

    Replace the following:

    • WORKER_POOL: the name of your Cloud Run worker pool.
    • IMAGE_URL: a reference to the container image thatcontains the worker pool, such asus-docker.pkg.dev/cloudrun/container/worker-pool:latest
    • NAME andVALUE: the name and values of the environmentvariables.
  3. Create or update the worker pool using the following command:

    gcloudbetarunworker-poolsreplaceworkerpool.yaml

Terraform

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

resource"google_cloud_run_v2_worker_pool""default"{name="WORKER_POOL"location="REGION"launch_stage="BETA"template{containers{image="IMAGE_URL"env{name="KEY1"value="VALUE1"}env{name="KEY2"value="VALUE2"}}}}

Replace the following:

  • WORKER_POOL: the name of the worker pool.
  • REGION: the Google Cloud region—for example,europe-west1
  • IMAGE_URL: a reference to the container image thatcontains the worker pool, such asus-docker.pkg.dev/cloudrun/container/worker-pool:latest
  • KEY1 andVALUE1: the environment variable andvalue. Optionally add more variables and values as needed.

Set default environment variables in the container

You can use theENVstatement in a Dockerfile to set default values for environment variables:

ENVKEY1=VALUE1,KEY2=VALUE2

Order of precedence: container versus worker pool variables

If youset a default environment variable in the container and alsoset an environment variable with the same name on theCloud Run worker pool, the value set on the worker pool takesprecedence.

Set multiple environment variables

You can set multiple environment variables by using the.env file or the--set-env-vars flag.

Set multiple environment variables using the.env file

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. SelectWorker pools from the menu, and clickDeploy container toconfigure a new worker pool.If you are configuring an existing worker pool, click theworker pool, then clickEdit and deploy new revision.

  3. If you are configuring a new worker pool, fill out the initial workerpool page, then clickContainer(s), Volumes, Networking, Security to expand theworker pools configuration page.

  4. Click theContainer tab.

    image

    • In the Variables & Secrets tab, clickAdd Variable and paste the contents ofyour.env file into theName field. Cloud Run automaticallypopulates theValue field and creates new variables for each key-value pairyou define in the.env file.
  5. ClickCreate orDeploy.

gcloud

To specify multiple environment variables from the.env file, run the followingcommand:

gcloud beta run worker-pools deployWORKER_POOL --imageIMAGE_URL --env-vars-file=ENV_FILE_PATH

Replace the following:

  • WORKER_POOL: the name of the worker pool.
  • IMAGE_URL: a reference to the container image thatcontains the worker pool, such asus-docker.pkg.dev/cloudrun/container/worker-pool:latest
  • ENV_FILE_PATH: path to the.env file.

Set multiple environment variables using the--set-env-vars flag

If you have multiple environment variables that cannot be listed inKEY1=VALUE1,KEY2=VALUE2format, you can repeat the--set-env-vars flag multiple times:
[...]--set-env-vars"KEY1=VALUE1"\--set-env-vars"KEY2=VALUE2"\--set-env-vars"KEY3=VALUE3"

Escape comma characters

Because the comma character, is used to split environment variables, if yourenvironment variable contains comma characters as values, you need toescape those delimiters by specifying a differentdelimiter character, for example,@:
--set-env-vars"^@^KEY1=value1,value2,value3@KEY2=..."

Update environment variables

You can update runtime environment variables for existing worker pools. This is anon-destructive approach that changes or adds runtime environment variables,but doesn't delete them.

You can update environment variables in Google Cloud console, the Google Cloud CLI,YAML, or Terraform:

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. SelectWorker pools from the menu, and click theworker pool you are updating, then clickEdit and deploy new revision.

  3. ClickContainer(s), Volumes, Networking, Security to expand theworker pools configuration page.

  4. Click theVariables & Secrets tab.

    image

  5. Locate the environment variable you want to update, then specify a different name forthe variable, or a different value in theName andValue fields.

  6. ClickDeploy.

gcloud

To update environment variables of an existing worker pool, use the--update-env-vars flag:

gcloud beta run worker-pools updateWORKER_POOL --update-env-varsKEY1=VALUE1,KEY2=VALUE2

Replace the following:

  • WORKER_POOL: the name of your worker pool
  • KEY1=VALUE1,KEY2=VALUE2: the comma-separated list of variablenames and values

YAML

  1. Download the worker poolYAML configuration:

    gcloudbetarunworker-poolsdescribeWORKER_POOL--formatexport>workerpool.yaml
  2. Edit the name and value variables.

  3. Update the worker pool using the following command:

    gcloudbetarunworker-poolsreplaceworkerpool.yaml

Terraform

To update environment variables of an existing worker pool, open themain.tffile corresponding to the worker pool and edit the name and value variables.Then, run the command to apply the Terraform configuration.

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Delete environment variables

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. SelectWorker pools from the menu, and click theworker pool you are updating, then clickEdit and deploy new revision.

  3. ClickContainer(s), Volumes, Networking, Security to expand theworker pools configuration page.

  4. Click theVariables & Secrets tab.

    image

  5. Locate the environment variable you want to delete and click the trash icon at theright of theValue field to delete the environment variable.

  6. ClickDeploy.

gcloud

To selectively remove environment variables from an existing worker pool, usethe--remove-env-varsflag:

gcloud beta run worker-pools updateWORKER_POOL --remove-env-varsKEY1,KEY2

Replace the following:

  • WORKER_POOL: the name of your worker pool
  • KEY1,KEY2: the comma-separated list of variable names

Alternatively, clear all previously set environment variableswith the--clear-env-varsflag:

gcloud beta run worker-pools updateWORKER_POOL --clear-env-vars

ReplaceWORKER_POOL with the name of your worker pool.

View environment variable configuration for the worker pool

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. ClickWorker pools to display the list of deployed worker pools.

  3. Click the worker pool you want to examine to display its details pane.

  4. Click theContainers tab to display worker pool container configuration.

Sample code

For a code sample that shows how to access environment variables in your code,refer toHandling sensitive configuration with Secret Managerin the End user authentication tutorial.

What's next

You can use environment variables to set abuildpacksconfiguration. For language-specific details, see the buildpacks documentationfor:

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.