Staggered Deployment
the ability to deploy to all tenants (or a group of tenants), but with a specified delay between the start of each deploy.
we have 12 tenants for our enterprise and deploy to our QA and Staging environments nightly. It's convenient now to have a single Octo.exe command start deployments to all tenants, but having them start simultaneously causes a bit of a traffic jam. We would like to be able to stagger the start of each deploy by, say, 5 or 10 minutes. (of course, once 5 deploys are running, the built-in throttling takes over.)

-
James H commented
I also had to stagger multiple tenants as I changed the OctopusBypassDeploymentMutex to True, but one of the initial steps requires they all update the same file.I took the script that Bruce wrote in 2017 and modified it a bit.I created 2 variables, TenantNames - this is a comma delimited list of tenants, and SecondsIncrement - this is the amount of time to wait between each tenant.
$tenants = $OctopusParameters['TenantNames'];
$currentTenant = $OctopusParameters['Octopus.Deployment.Tenant.Name'];
$seconds = $OctopusParameters['SecondsIncrement'];$wait = 0;
$index = 0;$tenants.split(',') | foreach {
$tenant = $_;
if ($tenant -eq $currentTenant) {
$seconds = $index * $seconds;
[int]$Wait = [convert]::ToInt32($Seconds, 10);
Write-Host "Tenant : $tenant - Wait time : $wait seconds"
}$index++;
}Write-Host "Waiting for $Wait Seconds."
$Increment = 4
$retries = $Wait / $Increment
$counter = 1# Wait
if ($Wait -gt 0)
{
for($i=$Increment; $i -gt 0; $i--)
{
if ($Wait%$Increment -ne 0)
{
$tmp = "{0:N2}" -f ($retries * $i)
}
else
{
$tmp = $retries * $i
}Write-Host "Time Remaining: $tmp seconds"
Start-Sleep $retries
}
} -
Bruce Foust commented
I also had a need to stagger server deployments. I had to add a powershell wait step with the following code. (I don't remember where I pulled the example to give credit for the script.)
$seconds is the only parameter passed into the step for the initial wait.
if (($OctopusParameters['Octopus.Machine.Name'] -eq "SERVER3") -or ($OctopusParameters['Octopus.Machine.Name'] -eq "SERVER1T"))
{
[int]$Wait = [convert]::ToInt32($Seconds, 10) + 30
}
elseif ($OctopusParameters['Octopus.Machine.Name'] -eq "SERVER4")
{
[int]$Wait = [convert]::ToInt32($Seconds, 10) + 60
}
elseif ($OctopusParameters['Octopus.Machine.Name'] -eq "SERVER6")
{
[int]$Wait = [convert]::ToInt32($Seconds, 10) + 90
}
else
{
[int]$Wait = [convert]::ToInt32($Seconds, 10)
}Write-Host "Waiting for $Wait Seconds."
$Increment = 4
$retries = $Wait / $Increment
$counter = 1# Wait
if ($Wait -gt 0)
{
for($i=$Increment; $i -gt 0; $i--)
{
if ($Wait%$Increment -ne 0)
{
$tmp = "{0:N2}" -f ($retries * $i)
}
else
{
$tmp = $retries * $i
}
Write-Host "Time Remaining: $tmp seconds"
Start-Sleep $retries
}
}