Azure Web App - Slot Swap

Octopus.AzurePowerShell exported 2020-06-25 by harrisonmeister belongs to ‘Azure’ category.

Swaps an azure web app slot. Defaults to the deployment slot defined in the web app target.


Note This template is designed to run against an azure web app octopus target

Depends on Azure CLI and powershell to be installed on the running machine

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Azure Account

azureWebAppSwap.AzAccount =

null

Target Slot

azWebAppSwap.targetSlot =

null

Source Slot

azWebAppSwap.sourceSlot = #{Octopus.Action.Azure.DeploymentSlot}

null

Script body

Steps based on this template will execute the following PowerShell script.

$rg = $OctopusParameters["Octopus.Action.Azure.ResourceGroupName"]
$webAppName = $OctopusParameters["Octopus.Action.Azure.WebAppName"]
$destinationSlot = $OctopusParameters["azWebAppSwap.targetSlot"]
$sourceSlot = $OctopusParameters["azWebAppSwap.sourceSlot"]

if([string]::IsNullOrEmpty($sourceSlot))
{
	throw "value for source slot must be provided"
}

$cmdArgs = "-g $rg -n $webAppName -s $sourceSlot"

if(![string]::IsNullOrEmpty($destinationSlot)) {$cmdArgs += " --target-slot $destinationSlot"}

$cmd = "az webapp deployment slot swap $cmdArgs"

write-verbose "command being invoked: $cmd"

Invoke-Expression $cmd

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "f256502a-4143-4d29-914e-80e541b05783",
  "Name": "Azure Web App - Slot Swap",
  "Description": "Swaps an azure web app slot. Defaults to the deployment slot defined in the web app target.\n<hr />\n\n*<p>Note This template is designed to run against an azure web app octopus target </p>*\n*<p>Depends on Azure CLI and powershell to be installed on the running machine</p>*",
  "Version": 3,
  "ExportedAt": "2020-06-25T15:05:37.259Z",
  "ActionType": "Octopus.AzurePowerShell",
  "Author": "harrisonmeister",
  "Packages": [],
  "Parameters": [
    {
      "Id": "a204505b-f995-40ff-95b3-300638d9b9df",
      "Name": "azureWebAppSwap.AzAccount",
      "Label": "Azure Account",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "AzureAccount"
      }
    },
    {
      "Id": "0b3383f9-31ae-402c-af57-be3b82a3d5b9",
      "Name": "azWebAppSwap.targetSlot",
      "Label": "Target Slot",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "7e4ed213-d5bb-4725-b13f-78e366535479",
      "Name": "azWebAppSwap.sourceSlot",
      "Label": "Source Slot",
      "HelpText": null,
      "DefaultValue": "#{Octopus.Action.Azure.DeploymentSlot}",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$rg = $OctopusParameters[\"Octopus.Action.Azure.ResourceGroupName\"]\n$webAppName = $OctopusParameters[\"Octopus.Action.Azure.WebAppName\"]\n$destinationSlot = $OctopusParameters[\"azWebAppSwap.targetSlot\"]\n$sourceSlot = $OctopusParameters[\"azWebAppSwap.sourceSlot\"]\n\nif([string]::IsNullOrEmpty($sourceSlot))\n{\n\tthrow \"value for source slot must be provided\"\n}\n\n$cmdArgs = \"-g $rg -n $webAppName -s $sourceSlot\"\n\nif(![string]::IsNullOrEmpty($destinationSlot)) {$cmdArgs += \" --target-slot $destinationSlot\"}\n\n$cmd = \"az webapp deployment slot swap $cmdArgs\"\n\nwrite-verbose \"command being invoked: $cmd\"\n\nInvoke-Expression $cmd",
    "Octopus.Action.Azure.AccountId": "#{azureWebAppSwap.AzAccount}"
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-web-app-slot-swap.json",
  "Website": "/step-templates/f256502a-4143-4d29-914e-80e541b05783",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZ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