通过 ARM 模板部署时,Azure 函数暂存槽交换错误

标签 azure azure-devops azure-functions azure-resource-manager azure-pipelines-release-pipeline

我使用 ARM 模板创建了一个 Azure 函数应用程序(消费计划)。 在我部署代码并执行交换操作(VSTS 任务)后,生产槽和登台槽都有新代码。但我预计暂存槽在交换操作后会有旧代码,这是 Azure 函数中的已知错误吗?或者我需要做任何额外的事情

"resources": [
    {
      "name": "CampaignSyncJob",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2016-09-01",
      "dependsOn": [],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[concat(parameters('artifactsLocation'), '/', variables('linkedTemplateFolderName'), '/', variables('webAppTemplateFileName'), parameters('artifactsLocationSasToken'))]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "appServicePlanName": {
            "value": "[reference('ReleaseParams').outputs.webApp.value.appServicePlanName]"
          },
          "appServiceName": {
            "value": "[reference('ReleaseParams').outputs.webApp.value.appServiceName]"
          },
          "artifactsLocation": {
            "value": "[parameters('artifactsLocation')]"
          },
          "artifactsLocationSasToken": {
            "value": "[parameters('artifactsLocationSasToken')]"
          },
          "packageFolder": {
            "value": "CampaignSyncJob"
          },
          "packageFileName": {
            "value": "package.zip"
          },
          "appSettings": {
            "value": {
              "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]",
              "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]",
              "WEBSITE_CONTENTSHARE": "[toLower(variables('appServiceName'))]",
              "FUNCTIONS_EXTENSION_VERSION": "~2",
              "WEBSITE_NODE_DEFAULT_VERSION": "6.5.0",
              "MSDEPLOY_RENAME_LOCKED_FILES": "1",
              "AppInsights_InstrumentationKey": "[variables('appInsightsInstrumentationKey')]",
              "StickySetting": "StuckToProduction1"
            }
          },
          "slotAppSettings": {
            "value": {
              "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]",
              "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]",
              "WEBSITE_CONTENTSHARE": "[toLower(variables('appServiceName'))]",
              "FUNCTIONS_EXTENSION_VERSION": "~2",
              "WEBSITE_NODE_DEFAULT_VERSION": "6.5.0",
              "MSDEPLOY_RENAME_LOCKED_FILES": "1",
              "AppInsights_InstrumentationKey": "[variables('appInsightsInstrumentationKey')]",
              "StickySetting": "StuckToStaging1"
            }
          },
          "slotName": {
            "value": "[reference('ReleaseParams').outputs.webApp.value.appServiceSlotName]"
          },
          "appServiceLocation": {
            "value": "[reference('ReleaseParams').outputs.common.value.location]"
          },
          "slotSpecificAppSettingKeys": {
            "value": [
              "StickySetting"
            ]
          }
        }
      }
    },

部署函数应用的链接模板

{
      "condition": "[parameters('deployOnStagingSlot')]",
      "apiVersion": "2015-08-01",
      "name": "[concat(parameters('appServiceName'), '/', parameters('slotName'))]",
      "type": "Microsoft.Web/sites/slots",
      "location": "[parameters('appServiceLocation')]",
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
      },
      "dependsOn": [
      ],
      "resources": [
        {
          "condition": "[parameters('deployOnStagingSlot')]",
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[concat('Microsoft.Web/sites/', parameters('appServiceName'), '/slots/', parameters('slotName'))]",
            "[concat('Microsoft.Web/sites/', parameters('appServiceName'), '/slots/', parameters('slotName'), '/Extensions/MSdeploy')]"
          ],
          "properties": "[parameters('slotAppSettings')]"
        },
        {
          "condition": "[parameters('deployOnStagingSlot')]",
          "name": "MSDeploy",
          "type": "extensions",
          "location": "[parameters('appServiceLocation')]",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[concat('Microsoft.Web/sites/', parameters('appServiceName'), '/slots/', parameters('slotName'))]"
          ],
          "properties": {
            "packageUri": "[concat(parameters('artifactsLocation'), '/', parameters('packageFolder'), '/', parameters('packageFileName'), parameters('artifactsLocationSasToken'))]",
            "setParameters": {
              "IIS Web Application Name": "[parameters('slotName')]"
            }
          }
        }
      ]
    }

最佳答案

嗯,我知道要在函数应用程序内交换插槽,需要将应用程序设置 WEBSITE_CONTENTSHARE 更改为插槽特定设置。

有关此解决方案以及有关多个插槽的其他 ARM 问题,请查看 Gary Lumsden 的博客

关于通过 ARM 模板部署时,Azure 函数暂存槽交换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51959958/

相关文章:

node.js - 无法使用 React 处理 Azure Functions Html 响应 - Expo

Azure - 向所有其他角色发送消息并等待响应

azure - VSTS,如何始终到达工件目录?

Azure DevOps Rest Call 给出 401 状态代码

azure - 如何解析 "connection string is not formatted correctly"?

azure - 创建 azurerm_data_protection_backup_vault 时 Terraform 返回错误 "The resource type could not be found in the namespace"

Azure Devops Pipeline - Angular 13 到 Azure 应用服务错误

azure-devops - VSTS 构建未使用 .vdproj 生成 .msi 文件

azure - azure函数应用程序设置连接字符串值中密码中的分号

python - 如何使用python代码将Windows网络驱动器连接到具有Linux环境的Azure Function App