【问题标题】:ARM Template Custom Script Extension with paramaters that have a space带有空格的参数的 ARM 模板自定义脚本扩展
【发布时间】:2017-07-21 18:52:58
【问题描述】:

powershell -File './scripts/myscript.ps1' -Param1 "My Param"

部署自定义脚本扩展所需的语法是什么,该扩展调用 PowerShell 文件,其中包含空格的参数。到目前为止,这些都是我尝试过的,但都没有奏效。其中每一个都与我的 ARM 模板中的一样:

# Failed to being executing the script. Error from the logs on the VM: "VMExtensionProvisioningError"
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount \"', parameters('vstsAccount'), '\"')]"

# Failed in the same way.
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount \\\"', parameters('vstsAccount'), '\\\"')]"

# Ran, but the parameters entering my PowerShell file were wrapped in `ticks`
"[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount `\"', parameters('vstsAccount'), '`\"')]"

【问题讨论】:

  • 第一个应该可以,我不认为问题出在模板中。
  • @4c74356b41 - 你是对的。我又试了一次,它奏效了。这一定是我之前修复的脚本中的另一个问题。

标签: azure arm-template


【解决方案1】:

第一个转义变体是正确的。要在 ARM 模板中转义,请使用 \

【讨论】:

    【解决方案2】:

    创建一个变量来保存引号,然后连接你想要的字符串: https://stackoverflow.com/a/37293130/84395

    "variables": {
        "singleQuote": "'",
    },
    ...
    "[concat('powershell -File InstallVSTSAgent.ps1 -vstsAccount ', variables('singleQuote'), parameters('vstsAccount'), variables('singleQuote'))]"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 2014-06-05
      • 1970-01-01
      相关资源
      最近更新 更多