Azure Swap Slot Multiple Web Apps with the same Target Role/Environment


(Raph) #1

We are currently utilizing the Deploy Azure Web App step that evaluates deployment target by Role/Environment using tags. The issue is that we are expecting to have multiple azure web apps match a role/environment. As it stands, we have a deployment targets (Azure Web Apps) set up as such:
target: site-region1
role: test.domain.com
env: production
slot: preprod

target: site-region2
role: test.domain.com
env: production
slot: preprod

we have the roles selected, so the Deploy Azure Web App step works perfectly in deploying to both applications, however we are having issues when it comes time to swap slots. We wanted to utilize the custom Powershell script, but we have no way of it figuring out the name and resource group name of the target role web app without us having to hard-code web app names in the project variables. We would like to have the script figure out the list of azure web apps that are being targeted based on the target role and environment being deployed to, and then have them as an array of objects, and then in the script to swap slots, have a for-each loop and pass the web app name and resource group.

Is there a) an easier way to do this, and if not, b) which info should I output as a variable that would build an array of objects that have at least Web App Name and Resource Group?


(Shaun Marx) #2

Hi Raph, thanks for getting in touch,

You can use a “Run Azure PowerShell Script” step and choose to run the script on behalf of each deployment target using the same roles as those used for your web app deployment targets. This allows you to use the variables contributed by the web app deployment target as seen in our documentation here. Swapping a slot could then be done using something like the following:

Switch-AzureRmWebAppSlot -Name $OctopusParameters["Octopus.Action.Azure.WebAppName"] -SourceSlotName $OctopusParameters["Octopus.Action.Azure.DeploymentSlot"] -DestinationSlotName "Production" -ResourceGroupName $OctopusParameters["Octopus.Action.Azure.ResourceGroupName"]

Hope that helps,

Regards,
Shaun