You can set environment variables by using gcloud command or through GCP Console [1]:
By using gcloud command:
You can use the --set-env-vars flag to define a variable using the gcloud command-line.
e.g.:
gcloud functions deploy FUNCTION_NAME --set-env-vars env1=whatever,env2=whatever FLAGS...
*Note: The --set-env-vars and --env-vars-file flags for environment variables are destructive. That is, they replace all current variables with those provided at deployment. To make additive changes, use the --update-env-vars flag described in the next section.
e.g.:
gcloud functions deploy FUNCTION_NAME --update-env-vars env1=whatever
Through GCP Console:
Open the Functions Overview page in the GCP Console:
GO TO THE CLOUD FUNCTIONS OVERVIEW PAGE.
Click Create function.
Fill in the required fields for your function.
Expand the advanced settings by clicking More.
In the Environment variables section, set variables by clicking Add variable.
References:
[1] https://cloud.google.com/functions/docs/env-var#setting_environment_variables