This page describes how to configure environment variables for your Cloud Run job.
When you set environment variables, they are injected into the container and are accessible to your code. Environment variables are set as key/value pairs.
Reserved names
The environment variables defined in the container runtime contract are reserved and cannot be set.
Maximum number of environment variables
Note that you can set a maximum of 1000 environment variables per container for each Cloud Run job.
Required roles
To get the permissions that you need to configure Cloud Run jobs, ask your administrator to grant you the following IAM roles on job:
-
Cloud Run Developer (
roles/run.developer
) - the Cloud Run job -
Service Account User (
roles/iam.serviceAccountUser
) - the service identity
For a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run job interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Set environment variables
You can set environment variables for new and existing jobs. Note that the
--set-env-vars
flag is a destructive action that deletes previously set
environment variables not included in the new list of environment variables.
You can set environment variables using the Google Cloud console, the gcloud CLI, or a YAML file:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Select Jobs from the menu, and click Deploy container to fill out the initial job settings page. If you are configuring an existing job, select the job, then click Edit.
Click Container(s), Volumes, Connections, Security to expand the job properties page.
Click the Variables tab.
- In the Variables & Secrets tab, click Add Variable and specify the name and value that you want for the variable in the Name and Value fields. For more information on how to set multiple environment variables or escape special characters, see Set multiple environment variables.
Click Create or Update.
gcloud
To specify environment variables when you
create a job, use the --set-env-vars
flag:
gcloud run jobs create JOB_NAME --image IMAGE_URL --set-env-vars KEY1=VALUE1,KEY2=VALUE2
Replace the following:
- JOB_NAME: the name of your job.
- KEY1=VALUE1,KEY2=VALUE2: comma-separated list of variable names and their values.
- IMAGE_URL: a reference to the
container image—for
example,
us-docker.pkg.dev/cloudrun/container/job:latest
.
For more information on how to set multiple environment variables or escape special characters, see Set multiple environment variables.
YAML
If you are creating a new job, skip this step. If you are updating an existing job, download its YAML configuration:
gcloud run jobs describe JOB_NAME --format export > job.yaml
- Update the
name
andvalue
attributes underenv
as shown undercontainers:
:
apiVersion: run.googleapis.com/v1 kind: Job metadata: name: JOB spec: template: spec: template: spec: containers: - image: IMAGE env: - name: KEY-1 value: VALUE-1 - name: KEY-N value: VALUE-N
Replace KEY-1, VALUE-1 with the environment variable and value. Optionally add more variables and values as needed.
You can also specify more configuration such as environment variables or memory limits.
- Update the
Update the existing job configuration:
gcloud run jobs replace job.yaml
Terraform
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
Add the following to agoogle_cloud_run_v2_job
resource in your Terraform configuration:resource "google_cloud_run_v2_job" "default" {
name = "JOB_NAME"
location = "REGION"
template {
template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/job"
env {
name = "KEY-1"
value = "VALUE-1"
}
env {
name = "KEY-N"
value = "VALUE-N"
}
}
}
}
}
Replace the following:
- JOB_NAME: the name of your Cloud Run job.
- REGION: the Google Cloud region. For example,
europe-west1
. - KEY-1: the environment variable.
- VALUE-1: the value associated with the key.
Optionally add more env
blocks to set additional environment variables.
Set default environment variables in the container
You can use the ENV
statement in a Dockerfile to set default values for environment variables:
ENV KEY1=VALUE1,KEY2=VALUE2
Order of precedence: container versus job variables
If you set a default environment variable in the container and also set an environment variable with the same name on the Cloud Run job, the value set on the job takes precedence.
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
In the Google Cloud console, go to the Cloud Run jobs page:
Select Jobs from the menu, and click Deploy container to fill out the initial job settings page. If you are configuring an existing job, select the job, then click Edit.
Click Container(s), Volumes, Connections, Security to expand the job properties page.
Click the Container tab.
- In the Variables & Secrets tab, click Add Variable
and paste the contents of your
.env
file into the Name field. Cloud Run automatically populates the Value field and creates new variables for each key-value pair you define in the.env
file.
- In the Variables & Secrets tab, click Add Variable
and paste the contents of your
Click Create or Update.
gcloud
To specify multiple environment variables from the .env
file, run the following
command:
gcloud beta run jobs create JOB_NAME --image=IMAGE_URL --env-vars-file=ENV_FILE_PATH
Replace the following:
- JOB_NAME: the name of your Cloud Run job.
- IMAGE_URL: a reference to the
container image—for
example,
us-docker.pkg.dev/cloudrun/container/job: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 in KEY1=VALUE1,KEY2=VALUE2
format, 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 your
environment variable contains comma characters as values, you need to
escape those delimiters by specifying a different
delimiter character, for example, @
:
--set-env-vars "^@^KEY1=value1,value2,value3@KEY2=..."
Update environment variables
You can update environment variables for existing jobs. This is a non-destructive approach that changes or adds environment variables, but doesn't delete previously set environment variables.
Console
To update environment variables using the Google Cloud console:
In the Google Cloud console, go to Cloud Run:
Select your job from the list, and click Edit and deploy new revision.
Click the Container tab.
In the Variables and secrets tab, edit the Name or Value fields, and click Done.
Click Deploy.
gcloud
To update environment variables of an existing job, use the
--update-env-vars
flag:
gcloud run jobs update JOB_NAME --update-env-vars KEY1=VALUE1,KEY2=VALUE2
Replace the following:
- JOB_NAME: the name of your job.
- KEY1=VALUE1,KEY2=VALUE2: comma-separated list of variable names and values.
View environment variables settings
To view the current environment variables settings for your Cloud Run job:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click the job you are interested in to open the Job details page.
Click View and Edit job configuration.
Locate the environment variables setting in the configuration details.
gcloud
Use the following command:
gcloud run jobs describe JOB_NAME
Locate the environment variables setting in the returned configuration.
Delete environment variables
You can delete environment variables for existing jobs.
Console
To delete environment variables using the Google Cloud console:
In the Google Cloud console, go to Cloud Run:
Select your job from the list, and click Edit and deploy new revision.
Click the Container tab.
In the Variables and secrets tab, move your cursor to the left of the Value field of the environment variable you are removing, to display the
Delete icon, and click it.Click Done.
Click Deploy.
gcloud
To selectively remove environment variables of an existing job, use the
--remove-env-vars
flag:
gcloud run jobs update JOB_NAME --remove-env-vars KEY1,KEY2
Replace the following:
- JOB_NAME: the name of your job.
- KEY1,KEY2: comma-separated list of variable names.
Alternatively, clear all previously set environment variables
with the --clear-env-vars
flag:
gcloud run jobs update JOB_NAME --clear-env-vars
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 2025-08-25 UTC.