Octopus.AzurePowerShell exported 2018-02-27 by MarkDordoy belongs to ‘Azure’ category.
This template will create an azure deployment slot. This step template should be placed before the “Deploy an Azure App” Octopus Deploy template and be used with its sister step “Switch Azure RM Deployment Slot”
This should be used for green-blue deployments, as referenced in this document: https://octopus.com/docs/deploying-applications/deploying-to-azure/deploying-a-package-to-an-azure-web-app/using-deployment-slots-with-azure-web-apps
NB: This step will promote your web app service plan to standard if it is currently using free, shared or basic tier
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
ResourceGroupName
ResourceGroupName =
Enter the name of the resource group you are deploying this Web App into
AppServicePlanName
AppServicePlanName =
Enter the name of the app service plan
AppName
AppName =
Enter the name of your web/api/etc app
AzureAccount
AzureAccount =
Enter the SPN used to connect to Azure
SlotName
SlotName =
Enter the name you wish to call your deployment slot
Script body
Steps based on this template will execute the following undefined script.
###############################################
# Create Azure RM Staging Deployment Slot
###############################################
##Step1: Get Variables
$ResourceGroupName = $OctopusParameters["ResourceGroupName"]
$AppName = $OctopusParameters["AppName"]
$stagingSlotName = $OctopusParameters["SlotName"]
$AppServicePlanName = $OctopusParameters["AppServicePlanName"]
###############################################
###############################################
Function Add-DeploymentSlotFunctionaility
{
[cmdletbinding()]
param
(
[string]$ResourceGroupName,
[string]$AppName,
[string]$AppServicePlanName
)
try
{
write-output "Will make sure the service plan can support deployment slots"
$servicePlan = Get-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName
if(($servicePlan.Sku.Tier.ToLower() -eq "free" ) -or ($servicePlan.Sku.Tier.ToLower() -eq "shared" ) -or ($servicePlan.Sku.Tier.ToLower() -eq "basic" ))
{
Write-Warning "Service plan does not currently support deployment slots, will now scale to standard tier"
$planUpdate = Set-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName -Tier "Standard"
Write-Output "Plan updated"
$planUpdate | Out-String | Write-Verbose
write-output "Plan Tier now set to:"
$planUpdate.Sku | Out-String | Write-Output
}
else
{
Write-Output "Service plan already supports deployment slots"
}
}
catch
{
throw "Error adding Deployment Slot functionailty. $_"
}
}
Function Invoke-RequiredVariablesCheck
{
if([string]::IsNullOrEmpty($ResourceGroupName))
{
Write-Error "ResourceGroupName variable is not set"
}
if([string]::IsNullOrEmpty($AppName))
{
write-error "AppName variable is not set"
}
if([string]::IsNullOrEmpty($stagingSlotName))
{
write-error "stagingSlotName variable is not set"
}
if([string]::IsNullOrEmpty($AppServicePlanName))
{
write-error "AppServicePlanName variable is not set"
}
Write-Verbose "Variables in use are:"
write-verbose "ResourceGroupName:$ResourceGroupName"
write-verbose "AppName:$AppName"
write-verbose "stagingSlotName:$stagingSlotName"
write-verbose "AppServicePlanName:$AppServicePlanName"
}
$ErrorActionPreference = "Stop"
try
{
Invoke-RequiredVariablesCheck
Add-DeploymentSlotFunctionaility -ResourceGroupName $ResourceGroupName -AppName $AppName -AppServicePlanName $AppServicePlanName
Write-output "Preparing Deployment Staging slot"
$deploymentSlot = Get-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName -ErrorAction SilentlyContinue
if($deploymentSlot.Id -eq $null)
{
Write-output "No current deployment slot created, will create one now"
New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName
}
else
{
Write-Verbose "Current slot exists, will remove to speed up deployment"
Remove-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName -Force
Write-Verbose "Slot removed"
New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName
}
Write-Output "Deployment slot $stagingSlotName created"
}
catch
{
Write-Error "Error in Create Azure RM Staging Deployment Slot step. $_"
}
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "10f6021e-27bd-47c5-9f10-4a1599182d8a",
"Name": "Create Azure Staging Deployment Slot",
"Description": "This template will create an azure deployment slot. This step template should be placed before the \"Deploy an Azure App\" Octopus Deploy template and be used with its sister step \"Switch Azure RM Deployment Slot\"\n\nThis should be used for green-blue deployments, as referenced in this document: https://octopus.com/docs/deploying-applications/deploying-to-azure/deploying-a-package-to-an-azure-web-app/using-deployment-slots-with-azure-web-apps\n\nNB: This step will promote your web app service plan to standard if it is currently using free, shared or basic tier",
"Version": 2,
"ExportedAt": "2018-02-27T11:24:00.844Z",
"ActionType": "Octopus.AzurePowerShell",
"Author": "MarkDordoy",
"Parameters": [
{
"Id": "37e14646-c52f-497a-a17b-2f17e9b1a629",
"Name": "ResourceGroupName",
"Label": "ResourceGroupName",
"HelpText": "Enter the name of the resource group you are deploying this Web App into",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "46bf87cd-342d-4095-bd2f-78d6a495faf5",
"Name": "AppServicePlanName",
"Label": "AppServicePlanName",
"HelpText": "Enter the name of the app service plan",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "54b04906-e716-4b1d-93c9-965f3a412c28",
"Name": "AppName",
"Label": "AppName",
"HelpText": "Enter the name of your web/api/etc app",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "15176529-6bc9-4e0f-82ab-b2e004959d9e",
"Name": "AzureAccount",
"Label": "AzureAccount",
"HelpText": "Enter the SPN used to connect to Azure",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "30da9c4b-1fb4-425e-a5f4-2338d24ca23b",
"Name": "SlotName",
"Label": "SlotName",
"HelpText": "Enter the name you wish to call your deployment slot",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
}
],
"Properties": {
"Octopus.Action.Azure.AccountId": "#{AzureAccount}",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.ScriptBody": "###############################################\n# Create Azure RM Staging Deployment Slot\n###############################################\n##Step1: Get Variables\n$ResourceGroupName = $OctopusParameters[\"ResourceGroupName\"] \n$AppName = $OctopusParameters[\"AppName\"] \n$stagingSlotName = $OctopusParameters[\"SlotName\"]\n$AppServicePlanName = $OctopusParameters[\"AppServicePlanName\"] \n###############################################\n###############################################\nFunction Add-DeploymentSlotFunctionaility\n{\n [cmdletbinding()]\n param\n ( \n [string]$ResourceGroupName,\n [string]$AppName,\n [string]$AppServicePlanName\n )\n try \n {\n write-output \"Will make sure the service plan can support deployment slots\"\n $servicePlan = Get-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName\n \n if(($servicePlan.Sku.Tier.ToLower() -eq \"free\" ) -or ($servicePlan.Sku.Tier.ToLower() -eq \"shared\" ) -or ($servicePlan.Sku.Tier.ToLower() -eq \"basic\" ))\n {\n Write-Warning \"Service plan does not currently support deployment slots, will now scale to standard tier\"\n $planUpdate = Set-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName -Tier \"Standard\"\n Write-Output \"Plan updated\"\n $planUpdate | Out-String | Write-Verbose\n write-output \"Plan Tier now set to:\"\n $planUpdate.Sku | Out-String | Write-Output\n }\n else \n {\n Write-Output \"Service plan already supports deployment slots\" \n } \n }\n catch \n {\n throw \"Error adding Deployment Slot functionailty. $_\" \n }\n}\n\nFunction Invoke-RequiredVariablesCheck\n{\n if([string]::IsNullOrEmpty($ResourceGroupName))\n {\n Write-Error \"ResourceGroupName variable is not set\"\n }\n\n if([string]::IsNullOrEmpty($AppName))\n {\n write-error \"AppName variable is not set\"\n }\n\n if([string]::IsNullOrEmpty($stagingSlotName))\n {\n write-error \"stagingSlotName variable is not set\"\n }\n\n if([string]::IsNullOrEmpty($AppServicePlanName))\n {\n write-error \"AppServicePlanName variable is not set\"\n }\n Write-Verbose \"Variables in use are:\"\n write-verbose \"ResourceGroupName:$ResourceGroupName\"\n write-verbose \"AppName:$AppName\"\n write-verbose \"stagingSlotName:$stagingSlotName\"\n write-verbose \"AppServicePlanName:$AppServicePlanName\"\n}\n\n$ErrorActionPreference = \"Stop\"\n\ntry \n{\n Invoke-RequiredVariablesCheck\n Add-DeploymentSlotFunctionaility -ResourceGroupName $ResourceGroupName -AppName $AppName -AppServicePlanName $AppServicePlanName\n Write-output \"Preparing Deployment Staging slot\"\n $deploymentSlot = Get-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName -ErrorAction SilentlyContinue\n if($deploymentSlot.Id -eq $null)\n {\n Write-output \"No current deployment slot created, will create one now\"\n New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName\n }\n else \n { \n Write-Verbose \"Current slot exists, will remove to speed up deployment\"\n Remove-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName -Force\n Write-Verbose \"Slot removed\"\n New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $AppName -Slot $stagingSlotName \n }\n Write-Output \"Deployment slot $stagingSlotName created\"\n}\ncatch \n{\n Write-Error \"Error in Create Azure RM Staging Deployment Slot step. $_\" \n}",
"Octopus.Action.Package.FeedId": null,
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.PackageId": null
},
"Category": "Azure",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-create-staging-deployment-slot.json",
"Website": "/step-templates/10f6021e-27bd-47c5-9f10-4a1599182d8a",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJ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