Octopus.AzurePowerShell exported 2020-06-29 by xtreampb belongs to ‘Azure’ category.
Sets the traffic distribution between multiple web app slots.
Note This template is designed to run against an azure web app octopus target, but will not use the slot defined.
Depends on Azure CLI and powershell to be installed on the worker
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Azure Account
azWebAppSetTraffic.AzureAcct =
An Azure account with permissions to the subscription and web app being modified
Traffic Distribution
azWebAppSetTraffic.trafficDistro =
The distribution of traffic in percent (0-100). Each web app slot should be defined on a separate line. Any remaining percentage will automatically be applied to production.
*Example* ``` myOtherSlot=10 stage=30 ```
Script body
Steps based on this template will execute the following PowerShell script.
$webAppName = $OctopusParameters["Octopus.Action.Azure.WebAppName"]
$rg = $OctopusParameters["Octopus.Action.Azure.ResourceGroupName"]
$trafficDistro = $OctopusParameters["azWebAppSetTraffic.trafficDistro"]
$cmdArgs = "--name $webAppName --resource-group $rg"
$cmdAction = "clear"
write-host "Checking distribution"
if(![string]::IsNullOrEmpty($trafficDistro))
{
$distribution = ""
$trafficDistro -split "`n" | ForEach-Object { $distribution += "$_ "}
$distribution = $distribution.TrimEnd(' ')
$cmdArgs += " --distribution $distribution"
$cmdAction = "set"
}
$cmd = "az webapp traffic-routing $cmdAction $cmdArgs"
write-verbose "cmd to invoke: $cmd"
write-host "setting distributions"
invoke-expression $cmd
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": "36791d2d-aa55-4bc7-bee4-a0d12d73f78e",
"Name": "Azure Web App - Set Traffic",
"Description": "Sets the traffic distribution between multiple web app slots.\n<hr />\n\n*<p>Note This template is designed to run against an azure web app octopus target, but will not use the slot defined. </p>*\n*<p>Depends on Azure CLI and powershell to be installed on the worker</p>*",
"Version": 1,
"ExportedAt": "2020-06-29T16:52:24.007Z",
"ActionType": "Octopus.AzurePowerShell",
"Author": "xtreampb",
"Packages": [],
"Parameters": [
{
"Id": "53d1306d-691c-4739-a09a-8fc9d66c60d3",
"Name": "azWebAppSetTraffic.AzureAcct",
"Label": "Azure Account",
"HelpText": "An Azure account with permissions to the subscription and web app being modified",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "AzureAccount"
}
},
{
"Id": "1f788822-9980-44cc-9e9c-f87db5998dd5",
"Name": "azWebAppSetTraffic.trafficDistro",
"Label": "Traffic Distribution",
"HelpText": "<p>\nThe distribution of traffic in percent (0-100). Each web app slot should be defined on a separate line. Any remaining percentage will automatically be applied to production.\n</p><p>\n*Example*\n```\nmyOtherSlot=10\nstage=30\n```\n</p>",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "MultiLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Azure.AccountId": "#{azWebAppSetTraffic.AzureAcct}",
"Octopus.Action.Script.ScriptBody": "$webAppName = $OctopusParameters[\"Octopus.Action.Azure.WebAppName\"]\n$rg = $OctopusParameters[\"Octopus.Action.Azure.ResourceGroupName\"]\n\n$trafficDistro = $OctopusParameters[\"azWebAppSetTraffic.trafficDistro\"]\n\n$cmdArgs = \"--name $webAppName --resource-group $rg\" \n\n$cmdAction = \"clear\"\n\nwrite-host \"Checking distribution\"\nif(![string]::IsNullOrEmpty($trafficDistro))\n{\n\t$distribution = \"\"\n\n\t$trafficDistro -split \"`n\" | ForEach-Object { $distribution += \"$_ \"}\n\n\t$distribution = $distribution.TrimEnd(' ')\n \n $cmdArgs += \" --distribution $distribution\"\n \n $cmdAction = \"set\"\n}\n\n\n$cmd = \"az webapp traffic-routing $cmdAction $cmdArgs\"\n\nwrite-verbose \"cmd to invoke: $cmd\"\n\nwrite-host \"setting distributions\"\ninvoke-expression $cmd\n"
},
"Category": "Azure",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-web-app-set-traffic.json",
"Website": "/step-templates/36791d2d-aa55-4bc7-bee4-a0d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