尝试使用 PS 脚本中的参数进行简单部署:
$prefix = "xxx"
$location = "switzerlandnorth"
az deployment group create `
--name $timestamp `
--resource-group $resourceGroupName `
--mode incremental `
--verbose `
--template-file .\src\ops\scripts\arm.json `
--parameters "{ `"location`": { `"value`": `"$location`" },`"projectPrefix`": { `"value`": `"$prefix`" } }"
响应有错误:
Unable to parse parameter: { location: { value: switzerlandnorth }, projectPrefix: { value: xxx } }
从 PS1 脚本运行。
最佳答案
正如我们在错误中看到的,它无法解析参数。将参数传递给 az Deployment Group create
命令的正确方法是:
az deployment group create `
--name $timestamp `
--resource-group $resourceGroupName `
--mode "incremental" `
--verbose `
--template-file ".\src\ops\scripts\arm.json" `
--parameters '{ \"location\": { \"value\": \"switzerlandnorth\" },\"projectPrefix\": { \"value\": \"xxx\" } }'
更新:
如果您想在参数中传递 PowerShell 变量,您可以执行如下操作 -
$location = "switzerlandnorth"
$projectPrefix = "xxx"
$params = '{ \"location\": { \"value\": \" ' + $location + '\" },\"projectPrefix\": { \"value\": \"' + $projectprefix + '\" } }'
az deployment group create `
--name $timestamp `
--resource-group $resourceGroupName `
--mode "incremental" `
--verbose `
--template-file ".\src\ops\scripts\arm.json" `
--parameters $params
希望这有帮助!
关于azure - 无法使用 powershell 脚本中的 az cli 通过参数部署 Azure ARM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62674984/