Home > Back-end >  What is the right syntac for `--set-env-vars` in gcloud and `.ps1` file to set multiple env variable
What is the right syntac for `--set-env-vars` in gcloud and `.ps1` file to set multiple env variable

Time:10-27

I'm trying to deploy a function using gcloud and powershell.

While doing that I want to set multiple environment variables.

Current script looks like this

--set-env-vars folder_id=$FOLDER_ID,SECRET_NAME=$SECRET_NAME,GCP_PROJECT=$PROJECTID

And this sets only 'folder_id' and takes all the strings after the first = including the rest of commas and equal signs as its value.

I know I can also use env-var-file but as you can see I want these values to be variables people can dynamically set.

What is the right syntax to do this?

So far I've tried,

# with quotation mark
--set-env-vars "folder_id=$FOLDER_ID,SECRET_NAME=$SECRET_NAME,GCP_PROJECT=$PROJECTID"
# with equal from the beginning
--set-env-vars=folder_id=$FOLDER_ID,SECRET_NAME=$SECRET_NAME,GCP_PROJECT=$PROJECTID
# with quotation mark AND equal from the beginning
--set-env-vars="folder_id=$FOLDER_ID,SECRET_NAME=$SECRET_NAME,GCP_PROJECT=$PROJECTID"
# with square brackets
--set-env-vars=[folder_id=$FOLDER_ID,SECRET_NAME=$SECRET_NAME,GCP_PROJECT=$PROJECTID]
# Passing an array of strings
$ENV_VARS = @("folder_id=$FOLDER_ID","SECRET_NAME=$SECRET_NAME","GCP_PROJECT=$PROJECTID")
--set-env-vars=$ENV_VARS

Before I would go on the path to parse env.yml file from .ps1 and then execute deploying code, I wanna give it one more shot by asking the question here.

CodePudding user response:

Using a separate --set-env-vars for every variable like --set-env-vars folder_id=$FOLDER_ID --set-env-vars SECRET_NAME=$SECRET_NAME isn't an elegant solution but it works.

  • Related