Azure Web App - Disable app_offline

Octopus.Script exported 2021-09-17 by harrisonmeister belongs to ‘Azure’ category.

This step template will remove an app_offline file from an Azure WebApp to safely bring the app domain online following a deployment.

It requires a set of deployment credentials for the Azure Web App.

Required:

Notes:

  • Tested on Octopus 2021.2.
  • Tested with both Windows PowerShell and PowerShell Core on Linux.

Parameters

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

Azure Web App name

AzWebApp.DisableAppOffline.AzWebAppName =

Provide the Azure Web App name.

AppOffline file name

AzWebApp.DisableAppOffline.Filename = app_offline.htm

Optional: Choose the variation of the name of the app offline file. Default: app_offline.htm

Available options:

  • app_offline.htm
  • app_offline.html

Deployment username

AzWebApp.DisableAppOffline.Deployment.Username = $#{AzWebApp.DisableAppOffline.WebAppName}

Provide the user or application-scoped deployment username for the Azure Web App. Default: $#{AzWebApp.DisableAppOffline.WebAppName}.

Deployment password

AzWebApp.DisableAppOffline.Deployment.Password =

Provide the user or application-scoped deployment password for the Azure Web App.

Deployment REST API Url

AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl = https://#{AzWebApp.DisableAppOffline.AzWebAppName}.scm.azurewebsites.net/api/vfs

Optional: Provide a custom deployment REST API URL. Default is: https://#{AzWebApp.DisableAppOffline.AzWebAppName}.scm.azurewebsites.net/api/vfs.

Script body

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

$ErrorActionPreference = "Stop";
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

# Variables
$AzWebAppName = $OctopusParameters["AzWebApp.DisableAppOffline.AzWebAppName"]
$Filename = $OctopusParameters["AzWebApp.DisableAppOffline.Filename"]
$DeployUsername = $OctopusParameters["AzWebApp.DisableAppOffline.Deployment.Username"]
$DeployPassword = $OctopusParameters["AzWebApp.DisableAppOffline.Deployment.Password"]
$DeploymentUrl = $OctopusParameters["AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl"]

# Validation
if ([string]::IsNullOrWhiteSpace($AzWebAppName)) {
    throw "Required parameter AzWebApp.DisableAppOffline.AzWebAppName not specified"
}

if ([string]::IsNullOrWhiteSpace($Filename)) {
    throw "Required parameter AzWebApp.DisableAppOffline.Filename not specified"
}
if ([string]::IsNullOrWhiteSpace($DeployUsername)) {
    throw "Required parameter AzWebApp.DisableAppOffline.Deployment.Username not specified"
}
if ([string]::IsNullOrWhiteSpace($DeployPassword)) {
    throw "Required parameter AzWebApp.DisableAppOffline.Deployment.Password not specified"
}
if ([string]::IsNullOrWhiteSpace($DeploymentUrl)) {
    throw "Required parameter AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl not specified"
}

$DeploymentUrl = $DeploymentUrl.TrimEnd('/')

# Local variables
$StepName = $OctopusParameters["Octopus.Step.Name"]

Write-Verbose "AzWebApp.DisableAppOffline.AzWebAppName: $AzWebAppName"
Write-Verbose "AzWebApp.DisableAppOffline.Filename: $FileName"
Write-Verbose "AzWebApp.DisableAppOffline.Deployment.Username: $DeployUsername"
Write-Verbose "AzWebApp.DisableAppOffline.Deployment.Password: ********"
Write-Verbose "AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl: $DeploymentUrl"

Write-Verbose "Step Name: $StepName"

try {
    $credPair = "$($DeployUsername):$($DeployPassword)"
    $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
    $headers = @{ 
        Authorization = "Basic $encodedCredentials"
        # Ignore E-Tag
        "If-Match"    = "*" 
    }

    $filePathUri = "$DeploymentUrl/site/wwwroot/$filename"
    Write-Host "Invoking Delete request for '$filePathUri'"
    $response = Invoke-RestMethod -Method Delete -Uri $filePathUri -Headers $headers

    Write-Verbose "Response: $response"
}
catch {
    $ExceptionMessage = $_.Exception.Message
    $ErrorDetails = $_.ErrorDetails.Message
    $Message = "An error occurred invoking the Azure Web App REST API: $ExceptionMessage"
    if (![string]::IsNullOrWhiteSpace($ErrorDetails)) {
        $Message += "`nDetail: $ErrorDetails"
    }

    Write-Error $Message -Category ConnectionError
}

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": "143ba6fd-968f-4f24-980b-49e47aa98f71",
  "Name": "Azure Web App - Disable app_offline",
  "Description": "This step template will remove an app_offline file from an Azure WebApp to safely bring the app domain online following a deployment.\n\nIt requires a set of [deployment credentials](https://docs.microsoft.com/en-gb/azure/app-service/deploy-configure-credentials) for the Azure Web App.\n\n**Required:** \n- Credentials with access to the [Kudu VFS API](https://github.com/projectkudu/kudu/wiki/REST-API#vfs)\n\nNotes:\n\n- Tested on Octopus `2021.2`.\n- Tested with both Windows PowerShell and PowerShell Core on Linux.",
  "Version": 1,
  "ExportedAt": "2021-09-17T17:52:46.792Z",
  "ActionType": "Octopus.Script",
  "Author": "harrisonmeister",
  "Packages": [],
  "Parameters": [
    {
      "Id": "b847fd97-bc71-4c89-99fb-bd5c2327027a",
      "Name": "AzWebApp.DisableAppOffline.AzWebAppName",
      "Label": "Azure Web App name",
      "HelpText": "Provide the Azure Web App name.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "0b2edf69-da0d-4750-882a-4036c67f0129",
      "Name": "AzWebApp.DisableAppOffline.Filename",
      "Label": "AppOffline file name",
      "HelpText": "*Optional:* Choose the variation of the name of the app offline file. Default: `app_offline.htm`\n\nAvailable options:\n\n- `app_offline.htm`\n- `app_offline.html`",
      "DefaultValue": "app_offline.htm",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "app_offline.htm|app_offline.htm\napp_offline.html|app_offline.html"
      }
    },
    {
      "Id": "c873f396-0ca1-4df9-b083-860541d24b61",
      "Name": "AzWebApp.DisableAppOffline.Deployment.Username",
      "Label": "Deployment username",
      "HelpText": "Provide the user or application-scoped [deployment](https://docs.microsoft.com/en-gb/azure/app-service/deploy-configure-credentials) username for the Azure Web App. Default: `$#{AzWebApp.DisableAppOffline.WebAppName}`.",
      "DefaultValue": "$#{AzWebApp.DisableAppOffline.WebAppName}",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "1c18f666-c91d-411c-a86b-b92d0bddc4ed",
      "Name": "AzWebApp.DisableAppOffline.Deployment.Password",
      "Label": "Deployment password",
      "HelpText": "Provide the user or application-scoped [deployment](https://docs.microsoft.com/en-gb/azure/app-service/deploy-configure-credentials) password for the Azure Web App.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Id": "023c4e13-2a25-4e29-916f-aaafea1d8284",
      "Name": "AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl",
      "Label": "Deployment REST API Url",
      "HelpText": "*Optional:* Provide a custom deployment REST API URL. Default is: `https://#{AzWebApp.DisableAppOffline.AzWebAppName}.scm.azurewebsites.net/api/vfs`.",
      "DefaultValue": "https://#{AzWebApp.DisableAppOffline.AzWebAppName}.scm.azurewebsites.net/api/vfs",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = \"Stop\";\n[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n# Variables\n$AzWebAppName = $OctopusParameters[\"AzWebApp.DisableAppOffline.AzWebAppName\"]\n$Filename = $OctopusParameters[\"AzWebApp.DisableAppOffline.Filename\"]\n$DeployUsername = $OctopusParameters[\"AzWebApp.DisableAppOffline.Deployment.Username\"]\n$DeployPassword = $OctopusParameters[\"AzWebApp.DisableAppOffline.Deployment.Password\"]\n$DeploymentUrl = $OctopusParameters[\"AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl\"]\n\n# Validation\nif ([string]::IsNullOrWhiteSpace($AzWebAppName)) {\n    throw \"Required parameter AzWebApp.DisableAppOffline.AzWebAppName not specified\"\n}\n\nif ([string]::IsNullOrWhiteSpace($Filename)) {\n    throw \"Required parameter AzWebApp.DisableAppOffline.Filename not specified\"\n}\nif ([string]::IsNullOrWhiteSpace($DeployUsername)) {\n    throw \"Required parameter AzWebApp.DisableAppOffline.Deployment.Username not specified\"\n}\nif ([string]::IsNullOrWhiteSpace($DeployPassword)) {\n    throw \"Required parameter AzWebApp.DisableAppOffline.Deployment.Password not specified\"\n}\nif ([string]::IsNullOrWhiteSpace($DeploymentUrl)) {\n    throw \"Required parameter AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl not specified\"\n}\n\n$DeploymentUrl = $DeploymentUrl.TrimEnd('/')\n\n# Local variables\n$StepName = $OctopusParameters[\"Octopus.Step.Name\"]\n\nWrite-Verbose \"AzWebApp.DisableAppOffline.AzWebAppName: $AzWebAppName\"\nWrite-Verbose \"AzWebApp.DisableAppOffline.Filename: $FileName\"\nWrite-Verbose \"AzWebApp.DisableAppOffline.Deployment.Username: $DeployUsername\"\nWrite-Verbose \"AzWebApp.DisableAppOffline.Deployment.Password: ********\"\nWrite-Verbose \"AzWebApp.DisableAppOffline.Deployment.KuduRestApiUrl: $DeploymentUrl\"\n\nWrite-Verbose \"Step Name: $StepName\"\n\ntry {\n    $credPair = \"$($DeployUsername):$($DeployPassword)\"\n    $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))\n    $headers = @{ \n        Authorization = \"Basic $encodedCredentials\"\n        # Ignore E-Tag\n        \"If-Match\"    = \"*\" \n    }\n\n    $filePathUri = \"$DeploymentUrl/site/wwwroot/$filename\"\n    Write-Host \"Invoking Delete request for '$filePathUri'\"\n    $response = Invoke-RestMethod -Method Delete -Uri $filePathUri -Headers $headers\n\n    Write-Verbose \"Response: $response\"\n}\ncatch {\n    $ExceptionMessage = $_.Exception.Message\n    $ErrorDetails = $_.ErrorDetails.Message\n    $Message = \"An error occurred invoking the Azure Web App REST API: $ExceptionMessage\"\n    if (![string]::IsNullOrWhiteSpace($ErrorDetails)) {\n        $Message += \"`nDetail: $ErrorDetails\"\n    }\n\n    Write-Error $Message -Category ConnectionError\n}"
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-web-app-disable-appoffline.json",
  "Website": "/step-templates/143ba6fd-968f-4f24-980b-49e47aa98f71",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJZQC8ez07sKlKTQlcLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzoUSnt8YxXlFuGHSbIaxvj+fip4btkLn1blkWLaF5v03yLhLOYlVuGYfMOMZzNGxCOzhjTJqFkXnjq3Dr1yyvPI3hGl3Ih3zzHHNKudRstRhX5O58vIcShY67Gq6EPIESlzUWvazaGAOGbvU7ArDu/g8M4o8opDZWvbvPzlL/MMBE8jT9T9W7PbAJlHPTBFRf9yVTEcs63msXz2UHLSgf650G/d5t+wjbxxB2UCMqGrk8/LFSD7uJMeNt5bcJCyQZyAe5Fo9KYfWS2flQrr4b4tpuzaeWjYs49rt9LHf9uZD7+VbyVi9EBNrjYjuq2sxQOrl+p+HuBVu45qvqfq691ttYFQ5KyKbyJgaIY/NGxrlWZwlwGvmvu1oY3PuAv0niTq6tZ78jk//9uc1r1r4lQki7y7sp2Tu4V1y2iLoqFTqi1lIGcpFiebrZNZ1dOkF0cCIlO8jQ47nCkam9Lilz9GhDF1I6XGLzfnhwDIIZVfI7+8SSgfHsijqXENOGJF5QorG4EcW0OrScqX/dDrXpr70Ut/BII+1OfECPuYz/NWxYmgrCsUskxPvyhgmrw+WGZ6lGTuOlIyCYWTFyWjpM5KIZRUIOwjRNYRQ6tZF9BXtk8hWAHPtLNJ727Fq0JSkC1FDRRF0Jalj0d5qVh2KEpM2TuSsCYTCT6ZkdmFYI9LrYp5QayWbo6NXlZwcRD/61pth5Fq5EX423QQxNjhqWvvklkljOLkYjrmphXPZOJOk6Pg7HKMsrtQKcowzZoK3rx1ZUelGMdQA/HaKkjAt2RgqpZeYqbNbH7Hp2ct4nqfSPOfe0ftiSTZJydOV6rG5bQbyLK+nRuCC0343PzDgiOXyQA5c14BTZi98uR/5KJ1SnatLdoO50WWBQZPTq0VgsklU3h932actuo17ayrHrb/3ykiegd3KbqF2wbV6RrlsJ07yLcpsWFTul9RyK6ZScr+tk7oNrFj0o7HQUlj4EiEvJ6rPLKSmlMZCrksl1OnLaRkxc+/HB1naMhNtT/6yM2bDs6azCRHrM3aVPN7aW8irD/10B8njpAMcsl8okXcdKrl4sPsLmQVy/Sj90ucPRc/d/Bxxj+dXSpCayen32D+hLi16MsIV8gfCXrYp6ySsiJKRUF0XXiLpVbFU+fNv4r7mOwhFsX4ZdwpSi1DYs2jb6ebZ9788cblTzMrYhu7sf/17IFdtuviJ2ioHA6pMHkoH4CLUeMBU7iGkxuM/YgcdderF9ibRdc7O982F1HpYhjfWUe+x5a6pjop9iNLfoePvlsdZdTSMwfxSmTY20Q0eHnUNzga1edeNmmqbg18aMVR1L9vwSXHF9TfIWBxpKLs2hj3eQeBC0USvp2HHF3eIkRdhFOd6ER8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA/I/4J8AAo/80BciBec4AAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Friday, September 17, 2021