visual-studio-code - 错误 : (gcloud. run.deploy) 参数 --set-env-vars: dict arg 语法错误

标签 visual-studio-code google-cloud-platform gcloud google-cloud-run google-cloud-code

我正在使用云代码(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 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

所以看来逗号需要转义。请问如何通过 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/

相关文章:

java - 如何设置数据存储,以便我可以通过非 App Engine Java 应用程序访问我的本地计算机

google-cloud-platform - 如何仅使用访问 token 通过 gcloud 进行身份验证?

fonts - 如何让 VS Code 更改斜体的字体粗细?

go - 如何摆脱在自动完成后VSCode的intellisense无法正常工作后出现的烦人文本框?

visual-studio-code - 在 Find In Files 中跳转到 "files to include"输入的快捷键

google-cloud-platform - 谷歌云计费API,抓取当月费用

git - Visual Studio Code/Git : Is there any way to prevent editing on master branch, 还允许 merge 吗?

java - 如何从 Google Cloud 上运行的 Java 应用安全地引用 .json 私钥文件

node.js - NodeJS + GCloud 日志记录中的内存泄漏