我正在尝试使用 AZDO 管道通过 ARM 模板部署虚拟机。 Microsoft 提供的示例模板和参数文件相当长,每个配置设置都是其自己的单独参数。我使用类似于以下格式的 JSON 对象压缩了参数文件:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"config": {
"location": "eastus"
"extensions": {
"extension1": {
"apiKey": ""
}
}
}
}
}
我们需要部署这些安装了特定扩展的虚拟机,其中一些扩展需要敏感信息才能正确配置。通常,如果“apiKey”字段是普通参数/与上面示例中的“config”参数处于同一级别,我将使用从 Key Vault 检索到的密钥覆盖管道任务中的参数,如下所示:
- task: AzureResourceManagerTemplateDeployment@3
inputs:
overrideParameters: '-apiKey $(extension1APIKey)'
但是,由于 apiKey 属性嵌套在多个属性中,我想知道以下内容是否正确:
- task: AzureResourceManagerTemplateDeployment@3
inputs:
overrideParameters: '-config.extensions.extension1.apiKey $(extension1APIKey)'
如果不是,覆盖嵌套属性/参数的正确方法是什么?
谢谢你。
我测试了你分享的模板参数文件,无效。
我可以按以下格式使用它:
模板参数文件:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"apiKeyvalue": {
"value": null
}
}
}
模板文件:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"apiKeyvalue": {
"type": "String"
}
},
"resources": [
{
//other Configurations
//...
"config": {
"location": "eastus",
"extensions": {
"extension1": {
"apiKey": "[parameters('apiKeyvalue')]"
}
}
}
}
]
}
您可以参考文档使用模板创建Windows虚拟机了解更多信息。