2
votes

I have created an Azure function app(consumption plan) using ARM template. After i deploy code and perform a swap operation(VSTS task) both the production and staging slot have the new code. But i expected the staging slot to have the old code after the swap operation, is this a known bug in Azure functions ? Or do i have to do anything extra

"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"
            ]
          }
        }
      }
    },

Linked template which deploys the function app

{
      "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')]"
            }
          }
        }
      ]
    }
1

1 Answers

1
votes

Hmm, I know that for swapping slots within a functions app it is required to change app setting WEBSITE_CONTENTSHARE to a slot specific setting.

For this solution and other ARM issues regarding multiple slots, check out the blog of Gary Lumsden