简体   繁体   中英

ERROR: (gcloud.run.deploy) argument --set-env-vars: Bad syntax for dict arg

I'm using Cloud Code (extension for Visual Studio Code) and during the deploy , via UI, I'm trying to set the Environment Variables field like this:

KEY1:value1
KEY2:value2,value3

But I'm having this error:

Failed to deploy the app. Error: ERROR: (gcloud.run.deploy) argument --set-env-vars: Bad syntax for dict arg: [value3]. Please see gcloud topic flags-file or gcloud topic escaping for information on providing list or dictionary flag values with special characters. ,Usage: gcloud run deploy [[SERVICE] --namespace=NAMESPACE] [optional flags] optional flags may be --add-cloudsql-instances | --allow-unauthenticated | --args | --async | --binary-authorization | --breakglass | --clear-binary-authorization | --clear-cloudsql-instances | --clear-config-maps | --clear-env-vars | --clear-key | --clear-labels | --clear-post-key-revocation-action-type | --clear-secrets | --clear-vpc-connector | --cluster | --cluster-location | --command | --concurrency | --connectivity | --context | --cpu | --cpu-throttling | --env-vars-file | --help | --image | --ingress | --key | --kubeconfig | --labels | --max-instances | --memory | --min-instances | --namespace | --platform | --port | --post-key-revocation-action-type | --region | --remove-cloudsql-instances | --remove-config-maps | --remove-env-vars | --remove-labels | --remove-secrets | --revision-suffix | --service-account | --set-cloudsql-instances | --set-config-maps | --set-env-vars | --set-secrets | --source | --tag | --timeout | --no-traffic | --update-config-maps | --update-env-vars | --update-labels | --update-secrets | --use-http2 | --vpc-connector | --vpc-egress For detailed information on this command and its flags, run: gcloud run deploy --help

So it seems the comma needs to be escaped. How to do that via Cloud Code UI , please?

If you set the env-var like this: --set-env-var "A=B,C,D" to gcloud, it will treat the comma (,) character as another environment variable declaration and will try to split the value into multiple environment variables. This is explained here in detail.

However, to prevent splitting with commas, you need to specify a different custom delimiter that you're sure won't occur in your value string, such as ##:

--set-env-vars "^##^A=B,C,D"

You may also use a format like this as mentioned in the official docs :

--set-env-vars "^@^KEY1=value1,value2,value3@KEY2=..."

I don't think there is a work around here. We are working to fix this through https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues/560 .

For now I could solve that by making "Environment Variables" UI field empty and using a Dockerfile to set the variables, where this syntax works:

ENV KEY1='value1'
ENV KEY2='value2,value3'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM