azure - 如何指定包含 & 符号的 Azure 应用程序配置值?

标签 azure azure-cli

我正在使用 Azure CLI 尝试将应用配置值设置为此 URL:

az appconfig kv set --key "mykey"--value "https://fake.com/action?param1=a¶m2=b"-n "test"--yes

我得到以下结果。请注意,这是来自 az 命令,而不是来自 shell。

Please specify config store name or connection string(suggested).
'param2' is not recognized as an internal or external command,
operable program or batch file.

是否有某种方法可以让 az 将这个 URL 作为值,而不必诉诸 URL 编码之类的愚蠢的东西?这对我来说似乎很糟糕。

另请注意,消息请指定配置存储名称或连接字符串(建议)。 是因为它无法正确解析命令行,因为这是使用 -n 指定的。如果我移动论点:

az appconfig kv set -n "test"--yes --key "mykey"--value "https://fake.com/action?param1=a¶m2=b"

我现在明白了:

{
  "contentType": null,
  "etag": "zuspBqPBOHR1mXfcKCgORXHpAxB",
  "key": "mykey",
  "label": null,
  "lastModified": "2021-08-31T17:39:14+00:00",
  "locked": false,
  "tags": {},
  "value": "https://fake.com/action?param1=a"
}
'param2' is not recognized as an internal or external command,
operable program or batch file.

这看起来更糟。它错误地创建了键值对,然后尝试将 param2 作为命令运行。搞什么?

最佳答案

通过@d-m 的链接之一,我找到了这个:

https://github.com/Azure/azure-cli/blob/dev/doc/quoting-issues-with-powershell.md

该链接充分解释了它,但基本上我需要在单引号内使用双引号,因为 Powershell 评估参数,然后 cmd 评估它们。因此,单引号被 powershell 去掉,然后双引号被 cmd 去掉,最后 az 得到了正确的参数。

这有效:

az appconfig kv set -n "test" --yes --key "mykey" --value '"https://fake.com/action?param1=a&param2=b"'
{
  "contentType": "text/plain",
  "etag": "XugiNgxa2I04w0gaG2OBh9Jcj75",
  "key": "mykey",
  "label": null,
  "lastModified": "2021-08-31T18:20:44+00:00",
  "locked": false,
  "tags": {},
  "value": "https://fake.com/action?param1=a&param2=b"
}

关于azure - 如何指定包含 & 符号的 Azure 应用程序配置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69003186/

相关文章:

sql-server - 表位于 sys.objects 中但不在表列表中

c# - 无法从表存储中获取记录

c# - 在分片之间迁移数据

json - 在 Azure 数据工厂中处理大型 JSON

azure - 无法在 Azure DevOps 管道中运行嵌套的 az cli 命令

azure - mac - az 命令未找到 azure

azure - 使用哪些 Azure CLI 命令来匹配门户服务企业应用中的列表

azure - 无法将 key 添加到 Azure key-Vault 支持的 Databricks 范围

azure - Azure CLI 和 Powershell cmdlet 之间的功能不一致

azure 搜索索引器因错误而停止