Configure environment variables for jobs Stay organized with collections Save and categorize content based on your preferences.
This page describes how to configure environment variables for yourCloud Run job.
When you setenvironment variables,they are injected into the container and are accessible to your code.Environment variables are set as key/value pairs.
Caution: Don't use environment variables to store and consume secrets,because environment variables are visible to anyone with project Viewerpermissions or greater. Instead, use Secret Manager withCloud Run as described in theUsing secrets page.Reserved names
The environment variables defined in thecontainer runtime contractare reserved and cannot be set.
Maximum number of environment variables
Note that you can set a maximum of1000 environment variables per container for eachCloud 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 withCloud Run, seeCloud Run IAM rolesandCloud Run IAM permissions.If your Cloud Run job 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 job usesservice identity to authenticate accessto Google Cloud APIs, never setGOOGLE_APPLICATION_CREDENTIALS as anenvironment variable on a Cloud Run job. Alwaysconfigure auser-managed service account instead.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 setenvironment variables not included in the new list of environment variables.
You can set environment variables using the Google Cloud console, thegcloud CLI, or a YAML file:
Console
In the Google Cloud console, go to the Cloud RunJobs page:
ClickDeploy container to fill outthe initial job settings page. If you are configuring an existing job,select the job, then clickView and edit job configuration.
ClickContainer(s), Volumes, Connections, Security to expand the job properties page.
Click theVariables tab.

- In the Variables & Secrets tab, clickAdd Variable and specify the name and value that you want for the variable in theName andValue fields. For more information on how to set multiple environment variables or escapespecial characters, seeSet multiple environment variables.
ClickCreate orUpdate.
gcloud
To specify environment variables when youcreate a job, use the--set-env-vars flag:
gcloud run jobs createJOB_NAME --imageIMAGE_URL --set-env-varsKEY1=VALUE1,KEY2=VALUE2Replace the following:
- JOB_NAME: the name of your job.
- KEY1=VALUE1,KEY2=VALUE2: comma-separated list ofvariable names and their values.
- IMAGE_URL: a reference to thecontainer image—forexample,
us-docker.pkg.dev/cloudrun/container/job:latest.
For more information on how to set multiple environment variables or escapespecial characters, seeSet multiple environment variables.
YAML
If you are creating a new job, skip this step.If you are updating an existing job, download itsYAML configuration:
gcloudrunjobsdescribeJOB_NAME--formatexport>job.yaml
- Update the
nameandvalueattributes underenvas shown undercontainers::
apiVersion:run.googleapis.com/v1kind:Jobmetadata:name:JOBspec:template:spec:template:spec:containers:-image:IMAGEenv:-name:KEY-1value:VALUE-1-name:KEY-Nvalue:VALUE-N
ReplaceKEY-1,VALUE-1 with the environment variableand value. Optionally add more variables and values as needed.
You can also specify more configuration such as environment variables ormemory limits.
- Update the
Update the existing job configuration:
gcloudrunjobsreplacejob.yaml
Terraform
To learn how to apply or remove a Terraform configuration, seeBasic 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 moreenv blocks to set additional environment variables.
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 job variables
If youset a default environment variable in the container and alsoset an environment variable with the same name on theCloud Run job, the value set on the job 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
In the Google Cloud console, go to the Cloud RunJobs page:
ClickDeploy container to fill outthe initial job settings page. If you are configuring an existing job,select the job, then clickView and edit job configuration.
ClickContainer(s), Volumes, Connections, Security to expand the job properties page.
Click theContainer tab.

- In the Variables & Secrets tab, clickAdd Variableand paste the contents of your
.envfile into theName field. Cloud Run automatically populates theValue field and createsnew variables for each key-value pair you define in the.envfile.
- In the Variables & Secrets tab, clickAdd Variableand paste the contents of your
ClickCreate orUpdate.
gcloud
To specify multiple environment variables from the.env file, run the followingcommand:
gcloud run jobs createJOB_NAME --image=IMAGE_URL --env-vars-file=ENV_FILE_PATHReplace the following:
- JOB_NAME: the name of your Cloud Run job.
- IMAGE_URL: a reference to thecontainer image—forexample,
us-docker.pkg.dev/cloudrun/container/job:latest. - ENV_FILE_PATH: path to the
.envfile.
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 environment variables for existing jobs. This is anon-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 the Cloud RunJobs page:
Select your job from the list, and clickEdit and deploy new revision.
Click theContainer tab.
In theVariables and secrets tab, edit theNameorValue fields, and clickDone.
ClickDeploy.
gcloud
To update environment variables of an existing job, use the--update-env-vars flag:
gcloud run jobs updateJOB_NAME --update-env-varsKEY1=VALUE1,KEY2=VALUE2Replace the following:
- JOB_NAME: the name of your job.
- KEY1=VALUE1,KEY2=VALUE2: comma-separated list of variablenames and values.
View environment variables settings
To view the current environment variables settings for yourCloud Run job:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click the job you are interested in to open theJob details page.
ClickView and Edit job configuration.
Locate the environment variables setting in the configurationdetails.
gcloud
Use the following command:
gcloudrunjobsdescribeJOB_NAMELocate the environment variables setting in the returnedconfiguration.
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 clickEdit and deploy new revision.
Click theContainer tab.
In theVariables and secrets tab, move your cursor to the left of theValue field of the environment variable you are removing, to displaytheDelete icon,and click it.
ClickDone.
ClickDeploy.
gcloud
To selectively remove environment variables of an existing job, use the--remove-env-varsflag:
gcloud run jobs updateJOB_NAME --remove-env-varsKEY1,KEY2Replace the following:
- JOB_NAME: the name of your job.
- KEY1,KEY2: comma-separated list of variable names.
Alternatively, clear all previously set environment variableswith the--clear-env-varsflag:
gcloud run jobs updateJOB_NAME --clear-env-varsExcept 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-18 UTC.
[8]ページ先頭