ARM 模板更新覆盖 Azure 函数中的某些内容导致错误 "The function runtime is unable to start"

ARM Template update overwrites something in Azure Function to cause error "The function runtime is unable to start"

如果我通过 Azure 门户创建一个 dotnet C# Azure Function Web 应用程序,我可以 (zip) 发布我的函数并且一切似乎都正常工作。如果我导航到门户中的功能,我可以看到为我创建的 function.json,并且一切似乎 运行 都很好。

然后,基于我们的基础架构即代码原则,作为我们在 Azure Dev Ops 中部署管道的一部分,我们执行一个 ARM 模板来更新 Function App,它具有我们从 Function App 复制的所有设置传送门。

在这个模板作为 运行 之后,当我们导航到门户中的函数时,我们反而得到:

Error:

The function runtime is unable to start.
Session Id: a3dd6ec59c9a459d947ef1ffbb9bf00b

Timestamp: 2020-01-04T23:31:08.741Z

我们没有看到 Function.json。 但是,该功能似乎仍然有效 (!)。如果我查看 Kudu 主机日志,则似乎没有任何错误,例如

2020-01-04T23:29:27.639 [Information] Starting JobHost
2020-01-04T23:29:27.641 [Information] Starting Host (HostId=dev-backend, InstanceId=b9a1e02b-faee-4a37-844c-412622583ff7, Version=2.0.12888.0, ProcessId=7440, AppDomainId=1, InDebugMode=True, InDiagnosticMode=False, FunctionsExtensionVersion=~2)
2020-01-04T23:29:27.670 [Information] Loading functions metadata
2020-01-04T23:29:27.699 [Information] 1 functions loaded
2020-01-04T23:29:27.860 [Information] Generating 1 job function(s)
2020-01-04T23:29:27.976 [Information] Found the following functions:
Consumer.Function.ConfigurationUpdated.ExecuteAsync
2020-01-04T23:29:28.097 [Information] Initializing function HTTP routes
No HTTP routes mapped
2020-01-04T23:29:28.105 [Information] Host initialized (449ms)
2020-01-04T23:29:28.459 [Information] Host started (810ms)
2020-01-04T23:29:28.459 [Information] Job host started
2020-01-04T23:29:33.474 [Information] Host lock lease acquired by instance ID 'e4e6f1cb6c07cd9bd67163acfe2dba75'.

我不确定 ARM 模板中可能缺少什么会导致它中断,或者在其他地方查找为什么 运行time 没有开始......或者即使它是完全可以正常工作。

我使用的模板是:

{
  "apiVersion": "2018-02-01",
  "name": "[variables('statisticsBackendContainer')]",
  "type": "Microsoft.Web/sites",
  "kind": "functionapp",
  "location": "[resourceGroup().location]",
  "tags": {
    "service": "statistics",
    "costCenter": "[parameters('costcentre')]",
    "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('servicePlan'))]": "Resource"
  },
  "dependsOn": [
    "[concat('Microsoft.Web/serverfarms/', variables('servicePlan'))]",
    "[concat('Microsoft.Sql/servers/', variables('databaseServer'))]",
    "[concat('Microsoft.Storage/storageAccounts/', variables('loggingStorageAccount'))]"
  ],
  "properties": {
    "name": "[variables('statisticsBackendContainer')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlan'))]",
    "clientAffinityEnabled": false,
    "httpsOnly": true,
    "hostingEnvironment": "",
    "siteConfig": {
      "phpVersion": "off",
      "Use32BitWorkerProcess": true,
      "AlwaysOn": true,
      "appSettings": [
        {
          "name": "AzureWebJobsStorage",
          "connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('loggingStorageAccount'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('loggingStorageAccount')), '2016-01-01').keys[0].value)]",
          "type": 3
        },
        {
          "name": "AppSettings:apiSecret",
          "value": "[variables('apiSecret')]"
        },
        {
          "name": "FUNCTIONS_WORKER_RUNTIME",
          "value": "dotnet"
        },
        {
          "name": "FUNCTIONS_EXTENSION_VERSION",
          "value": "~2"
        },
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(concat('microsoft.insights/components/',variables('statisticsBackendContainer')), '2015-05-01').InstrumentationKey]"
        }
      ],
      "connectionStrings": [
        {
          "name": "microsoft.servicebus.connectionstring",
          "connectionString": "[listkeys(variables('sendlistenServiceBusNamespace'), '2014-09-01').primaryConnectionString]",
          "type": 3
        },
        {
          "name": "statistics.connection",
          "connectionString": "[concat('Server=tcp:', reference(concat('Microsoft.Sql/servers/', variables('databaseServer'))).fullyQualifiedDomainName, ',1433;Database=', variables('databaseStatisticsName'), ';User Id=', parameters('appLogin'), '@', variables('serviceNameEnvironment'), ';Password=', parameters('appLoginPassword'), ';Encrypt=True;Connection Timeout=30;')]",
          "type": 2
        },
        {
          "name": "logging.connection",
          "connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('loggingStorageAccount'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('loggingStorageAccount')), '2016-01-01').keys[0].value)]",
          "type": 3
        },
        {
          "name": "management.webhook",
          "connectionString": "[concat('https://',variables('managementApiContainer'),'.azurewebsites.net')]",
          "type": 3
        }
      ]
    }
  }
},

最后我认为 ARM 模板具有误导性,因为部署的 Function 应用程序中缺少 AzureWebJobsStorage AppSetting。当我确定它在 ARM 模板中并重新部署时,Azure 门户中的一切似乎都正常工作。