FBryant87
FBryant87

Reputation: 4614

Detect if an Azure slot swap failed after deploying in ADO?

Currently when deploying our Azure functions we make use of the ADO pipeline task to deploy them:

- task: AzureFunctionApp@1
            displayName: 'Deploy Function'
            inputs:
              azureSubscription: 'our sub'
              appType: 'functionApp'
              appName: 'our app'
              deployToSlotOrASE: true
              slotName: 'staging'
              resourceGroupName: 'our-rg'
              package: '$(System.DefaultWorkingDirectory)/Artifact/build$(Build.BuildId).zip'
              deploymentMethod: 'auto'

We have auto-slot-swapping enabled so that, when we deploy, our code goes to our staging slot. This slot is warmed and, if successful, the slot is swapped into live.

Unfortunately this ADO task has no way of knowing if the slot swap was actually successful. The only visibility of this is in the Azure Portal activity log, and these logs show whether the swap was successful or not (and the code actually went live).

Is there a simple for approach for us to know from the ADO pipeline whether the swap was successful?

Upvotes: 1

Views: 771

Answers (2)

Zach Johnson
Zach Johnson

Reputation: 810

The only reliable way I've found to verify that a deployment succeeded to pre-production and that my auto-swap completed was by querying the kudu logs for the most recent deployment to the production slot. All other methods involving activity logs and otherwise gave flaky results. Since we are checking actual slot specific files we don't have to wait for logs to propagate and we know they are written at the time of deployment and represent the current code running on the slot.

We use an azure cli script similar to the following to perform this verification:

$localTimeZone = [System.TimeZoneInfo]::Local
az webapp log deployment list --name $appserviceName --resource-group $resourceGroup --subscription $subscription `
        | convertfrom-json `
        | Select-Object `
            @{Name="Active"; Expression={$_.active}}, `
            @{Name="Site"; Expression={$appserviceName}}, `
            @{Name="Time"; Expression={[System.TimeZoneInfo]::ConvertTimeFromUtc($_.start_time, $localTimeZone)}}, `
            @{Name="Status"; Expression={$_.status_text}}, `
            @{Name="Message"; Expression={$_.message}}, `
            @{Name="ProvisioningState"; Expression={$_.ProvisioningState}} 

Upvotes: 0

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

You could use Azure App Service Manage task to swap slot instead of enabling auto-slot-swapping. In this way, you could get the slot swapping status.

Upvotes: 0

Related Questions