我正在使用云代码(Visual Studio Code 的扩展),并且在部署期间,通过 UI,我尝试设置环境变量 字段如下:
KEY1:value1
KEY2:value2,value3
但是我遇到了这个错误:
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
orgcloud 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
所以看来逗号需要转义。请问如何通过 Cloud Code UI 执行此操作?
最佳答案
如果您像这样设置环境变量:--set-env-var "A=B,C,D"
to gcloud,它会将逗号 (,) 字符视为另一个字符环境变量声明并会尝试将值拆分为多个环境变量。这是解释here详细。
但是,为了防止用逗号分割,您需要指定一个确定不会出现在值字符串中的不同自定义分隔符,例如 ##:
--set-env-vars "^##^A=B,C,D"
您还可以使用 official docs 中提到的格式。 :
--set-env-vars "^@^KEY1=value1,value2,value3@KEY2=..."
关于visual-studio-code - 错误 : (gcloud. run.deploy) 参数 --set-env-vars: dict arg 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71851641/