Octopus.Script exported 2023-08-15 by mcasperson belongs to ‘Octopus’ category.
Determine Window Size for Rolling Deploy.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Perform Rolling Deploy?
DRDWSPerformRollingDeploy = True
If checkbox is unchecked, all servers will be deployed to.
NOTE: This can be set to use a variable or expression.
Server percentage to deploy
DRDWSServerPercentageToDeploy =
Percentage of servers to perform rolling deploy on at a time. Enter as whole number.
Example for 25%: 25
Server Role for Rolling Deploy
DRDWSServerRole =
null
Script body
Steps based on this template will execute the following PowerShell script.
#region Verify variables
#No need to verify PerformRollingDeploy as this is a checkbox and will always have a boolean value. Report value back for logging.
Try
{
$performRollingDeploy = [System.Convert]::ToBoolean($OctopusParameters['DRDWSPerformRollingDeploy'])
Write-Host ('Perform Rolling Deploy: ' + $performRollingDeploy)
}
Catch
{
Throw "Cannot convert Perform Rolling Deploy: '" + $OctopusParameters['DRDWSPerformRollingDeploy'] + "' to boolean value. Try having the expression or variable evaluate to 'True' or 'False'."
}
#Verify ServerPercentageToDeploy can be converted to integer.
If ([string]::IsNullOrEmpty($OctopusParameters['DRDWSServerPercentageToDeploy']))
{
Throw 'Server percentage to deploy cannot be null.'
}
[int]$serverPercentageToDeploy = 0
[bool]$result = [int]::TryParse($OctopusParameters['DRDWSServerPercentageToDeploy'], [ref]$serverPercentageToDeploy)
If ($result)
{
Write-Host ('Server percentage to deploy: ' + $serverPercentageToDeploy + '%')
$serverPercentToDisconnect = $serverPercentageToDeploy / 100
}
Else
{
Throw "Cannot convert Server percentage to deploy: '" + $OctopusParameters['DRDWSServerPercentageToDeploy'] + "' to integer."
}
#Verify ServerRole is not null.
If ([string]::IsNullOrEmpty($OctopusParameters['DRDWSServerRole']))
{
Throw 'Server Role for Rolling Deploy cannot be null.'
}
$role = $OctopusParameters['DRDWSServerRole']
Write-Host ('Server Role for Rolling Deploy: ' + $role)
#endregion
#region Process
$serverCountToDeployTo = 9999
If ($performRollingDeploy)
{
$servers = $OctopusParameters['Octopus.Environment.MachinesInRole[' + $role + ']']
$totalMachines = If ([string]::IsNullOrEmpty($servers)) { 0 } else { ($servers.Split(',')).Count }
$serverCountToDeployTo = [math]::Round(($totalMachines * $serverPercentToDisconnect))
Write-Host ('Total machines: ' + $totalMachines)
If ($serverCountToDeployTo -eq 0)
{
$serverCountToDeployTo++
}
}
Write-Host ('Window Size: ' + $serverCountToDeployTo)
#To use this value, set Window size value to: #{Octopus.Action[Determine Rolling Deploy Window Size].Output.WindowSize}
Set-OctopusVariable -name "WindowSize" -value $serverCountToDeployTo
#endregion
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": "cb1b825e-d945-43e4-a572-d945654ca9cc",
"Name": "Determine Rolling Deploy Window Size",
"Description": "Determine Window Size for Rolling Deploy.",
"Version": 3,
"ExportedAt": "2023-08-15T07:55:04.446Z",
"ActionType": "Octopus.Script",
"Author": "mcasperson",
"Parameters": [
{
"Id": "561333cc-14ea-44be-aca2-ccb06e0c582f",
"Name": "DRDWSPerformRollingDeploy",
"Label": "Perform Rolling Deploy?",
"HelpText": "If checkbox is unchecked, all servers will be deployed to. \nNOTE: This can be set to use a variable or expression.",
"DefaultValue": "True",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "ecf32591-130c-41cb-b8f5-405e3b1c5d28",
"Name": "DRDWSServerPercentageToDeploy",
"Label": "Server percentage to deploy",
"HelpText": "Percentage of servers to perform rolling deploy on at a time. Enter as whole number. \nExample for 25%: 25",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "bed9618f-6ede-4c6b-a4b1-a6f0d0a685d4",
"Name": "DRDWSServerRole",
"Label": "Server Role for Rolling Deploy",
"HelpText": null,
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
}
],
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
"Octopus.Action.Script.ScriptBody": "#region Verify variables\n\n#No need to verify PerformRollingDeploy as this is a checkbox and will always have a boolean value. Report value back for logging.\nTry\n{\n $performRollingDeploy = [System.Convert]::ToBoolean($OctopusParameters['DRDWSPerformRollingDeploy'])\n Write-Host ('Perform Rolling Deploy: ' + $performRollingDeploy)\n}\nCatch\n{\n Throw \"Cannot convert Perform Rolling Deploy: '\" + $OctopusParameters['DRDWSPerformRollingDeploy'] + \"' to boolean value. Try having the expression or variable evaluate to 'True' or 'False'.\"\n}\n\n#Verify ServerPercentageToDeploy can be converted to integer.\nIf ([string]::IsNullOrEmpty($OctopusParameters['DRDWSServerPercentageToDeploy']))\n{\n Throw 'Server percentage to deploy cannot be null.'\n}\n\n[int]$serverPercentageToDeploy = 0\n[bool]$result = [int]::TryParse($OctopusParameters['DRDWSServerPercentageToDeploy'], [ref]$serverPercentageToDeploy)\n\nIf ($result)\n{\n Write-Host ('Server percentage to deploy: ' + $serverPercentageToDeploy + '%')\n $serverPercentToDisconnect = $serverPercentageToDeploy / 100\n}\nElse\n{\n Throw \"Cannot convert Server percentage to deploy: '\" + $OctopusParameters['DRDWSServerPercentageToDeploy'] + \"' to integer.\"\n}\n\n#Verify ServerRole is not null.\nIf ([string]::IsNullOrEmpty($OctopusParameters['DRDWSServerRole']))\n{\n Throw 'Server Role for Rolling Deploy cannot be null.'\n}\n$role = $OctopusParameters['DRDWSServerRole']\nWrite-Host ('Server Role for Rolling Deploy: ' + $role)\n\n#endregion\n\n\n#region Process\n\n$serverCountToDeployTo = 9999\n\nIf ($performRollingDeploy)\n{\n $servers = $OctopusParameters['Octopus.Environment.MachinesInRole[' + $role + ']']\n $totalMachines = If ([string]::IsNullOrEmpty($servers)) { 0 } else { ($servers.Split(',')).Count }\n $serverCountToDeployTo = [math]::Round(($totalMachines * $serverPercentToDisconnect))\n\n Write-Host ('Total machines: ' + $totalMachines)\n\n If ($serverCountToDeployTo -eq 0)\n {\n $serverCountToDeployTo++\n }\n}\n\nWrite-Host ('Window Size: ' + $serverCountToDeployTo)\n\n#To use this value, set Window size value to: #{Octopus.Action[Determine Rolling Deploy Window Size].Output.WindowSize}\nSet-OctopusVariable -name \"WindowSize\" -value $serverCountToDeployTo\n\n#endregion\n",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.FeedId": null,
"Octopus.Action.Package.PackageId": null
},
"Category": "Octopus",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/determine-rolling-deploy-window-size.json",
"Website": "/step-templates/cb1b825e-d945-43e4-a572-d945654ca9cc",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAC1QTFRFT6Tl////L5Pg8vj9Y67omsvwPJrisdfzfbzs5fL7y+T32Ov5isLucLXqvt31CJPHWwAABMJJREFUeNrs3deW4jAMAFDF3U75/89dlp0ZhiU4blJEjvQ8hYubLJsA00UCBCIQgQhEIAIRiEAEIhCBCEQgAhGIQAQiEIEIhD8kJm+t+QprfdKfB9HbYpx6CWfspj8HMi+gMgHL/AmQA8W3JTKH+ALFvzCeL0RbpyoCPE9IJeNOSQwh5Z3qd6yRGWQ2qi2cZQWxqj1WzQYSjeoJmJlAklOd4VlArOqPhQEkqBERToeMcfRJBkC0Uep8CfBpjz4JsHJ0zF3dkEWNje0kiB/sUC6eApndaIiCMyAa1PiwJ0AWhRGJHJJQHG2dC7h1rNbO1QOxSA7lNCkkKrQIpJCAB1GREILYIC1NAiwbpKFJgGWDNExcwGstfExcZBCHC6nOglshHtmhViLIig1RNBCN7qjtW8C0Z1UvJcC1Z9XmwMBzzvobmgAyEzgq91dtEEsBsQSQQAFZCSBAATEEEApHZbrVBIkkEIUPSVeB+KtALA0kXQUSrwKZBCIQBnk8Y4i5CsReBe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