2

When swapping the production slot with a staging slot for a Azure App Service through the portal you get a little warning in case the configs differ between the slots.

I would like to get the same warning when I swap from command line (for example with az in bash), is that possible, and if so how to do it?

3 Answers 3

1

There does not seem to be any way to get a confirmation before the swap is completed using Azure CLI.

If you want a confirmation dialog you need to script it separately, e.g. like this

read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
    az webapp deployment slot swap  -g MyResourceGroup -n MyUniqueApp --slot staging --target-slot production
fi

References

  • see this page for more info about the swapping slots using the cli.
  • and this page for details on conditionally executing statements in bash
2
  • 1
    Do you have any suggestion as to how to script such a warning separately?
    – viblo
    Commented Apr 4, 2018 at 15:34
  • 1
    Sorry, maybe I was not clear. The warning Im talking about is the one that shows any config values that doesnt match between the slots.
    – viblo
    Commented Apr 5, 2018 at 7:39
1

Managed to do that using the Azure CLI and jq (install it first). That's the same call Azure portal does when doing the preview. So, I've added the Azure CLI task and then:

echo Phase One changes
az rest -m post -u https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/<your_rg>/providers/Microsoft.Web/sites/<your_webapp_name>/slots/<slot_name>/slotsdiffs?api-version=2016-08-01 --body {\"targetSlot\":\"production\"} | jq -r "[.value[].properties | select(.diffRule == \"SlotSettingsMissing\") | .description ] | join(\";\")" 

echo Phase Two changes
az rest -m post -u https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/<your_rg>/providers/Microsoft.Web/sites/<your_webapp_name>/slots/<slot_name>/slotsdiffs?api-version=2016-08-01 --body {\"targetSlot\":\"production\"} | jq -r "[.value[].properties | select(.diffRule != \"SlotSettingsMissing\") | .description ] | join(\";\")" 

Note, that the {subscriptionId} will be substituted so no need to do it manually. Other parameters in <> should be provided anyhow.

0

In the end I made a extension to the az cli that compares and diffs the configs. Was after all not very difficult to do, and at the same time I could extend its functionality a little bit and make it possible to also diff configs between different web apps, for example useful when the same service is deployed in more than one region.

(this extension is at the moment not publicly available anywhere, but could maybe if there was interest)

Not the answer you're looking for? Browse other questions tagged or ask your own question.