从Azure Release Pipelines部署ARM模板会删除代码

时间:2020-01-22 07:37:00

标签: azure azure-devops azure-web-app-service azure-resource-manager

根据documentation,“ ARM模板是幂等的,这意味着它可以执行任意次,并且每次都将得到相同的结果”。但是我刚刚了解到,当我重新部署AppService(无任何更改)时,它将删除我的应用程序。端点不再响应,也没有应用程序日志,因此我进入了Azure门户控制台,运行DIR,令我惊讶的是,那里唯一的文件是hostingstart.html!是否记录在某处?这完全改变了我在Release管道中处理ARM模板的方式。

我正在使用链接模板。在主模板中,我有以下资源:

{
      "name": "myApp",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "dependsOn": [
        "storage"
      ],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[uri(variables('templateBaseUrl'), 'myApp.json')]"
        },
        "parameters": {
          "env": {
            "value": "[parameters('env')]"
          },
          "myAppAppServiceSku": {
            "value": "[parameters('myAppAppServiceSku')]"
          },
          "storageAccountName": {
            "value": "[variables('storageAccountName')]"
          }
        }
      }
    }

和链接的模板

"resources": [
    {
      "name": "[variables('myAppServerFarmName')]",
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2018-02-01",
      "location": "[resourceGroup().location]",
      "tags": {
        "ENV": "[parameters('env')]"
      },
      "sku": {
        "name": "[parameters('myAppAppServiceSku')]"
      },
      "properties": {
      }
    },
    {
      "name": "[variables('myAppWebSiteName')]",
      "type": "Microsoft.Web/sites",
      "apiVersion": "2018-11-01",
      "dependsOn": [
        "[variables('myAppServerFarmName')]"
      ],
      "location": "[resourceGroup().location]",
      "tags": {
        "ENV": "[parameters('env')]"
      },
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('myAppServerFarmName'))]",
        "siteConfig": {
          "alwaysOn": true
        }
      },
      "resources": [
        {
          "name": "appSettings",
          "type": "config",
          "apiVersion": "2018-11-01",
          "dependsOn": [
            "[variables('myAppWebSiteName')]"
          ],
          "tags": {
            "ENV": "[parameters('env')]"
          },
          "properties": {
            "storageAccountName": "[parameters('storageAccountName')]",
            "storageKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName')), '2019-04-01').keys[0].value]"
          }
        }
      ]
    }
  ]

编辑: 我已经使用Kudu ZIP Deploy进行了部署检查。部署之后,重新部署ARM模板不会删除代码!因此它按预期工作。因此,从发布管道进行的部署在某些方面有所不同。

执行两个步骤后,一切看起来都很好。但是当我仅执行第一步时,应用程序代码就会被删除。 这就是现在的样子。

Release pipeline

每个步骤都有一个任务: ARM templates stage Deploy App stage

1 个答案:

答案 0 :(得分:0)

有关更多信息,请参见Azure Functions ARM template redeployment deletes my published functions。本质上,您需要将其添加到模板中:

{ "name": "WEBSITE_RUN_FROM_PACKAGE", "value": "1" }