且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 ARM 模板中有条件地设置 appsetting 值

更新时间:2022-06-27 02:52:52

只需创建一个依赖于参数的变量:

just create a variable that would depend on the parameter:

"parameters": {
...
"DeploymentType": {
    "type": "string",
    "allowedValues": [
        "Dev",
        "Prod"
    ]
}
...
"variables": {
    "Dev": "https://some_service-ci.domain.com",
    "Prod": "https://abc123.foo.bar.baz.com",
    "DeploymentVariable": "[variables(parameters('DeploymentType'))]",
...
"appSettings": [
    "name": "MY_SERVICE_URL", 
    "value": "[variables('DeploymentVariable')]"
]
...

好的,这是如何工作的.您传入参数DeploymentType",它可以是 PROD 或 DEV.如果您传递 DEV "DeploymentVariable": "[variables(parameters('DeploymentType'))]", - 这将评估为 "[variables('Dev')]"并获取"Dev"的值:"https://some_service-ci.domain.com",

Ok, so how does this work. you pass in the parameter 'DeploymentType', it can be PROD or DEV. If you pass DEV "DeploymentVariable": "[variables(parameters('DeploymentType'))]", - this evaluates to "[variables('Dev')]" and gets the value of "Dev": "https://some_service-ci.domain.com",