We want to restrict deployments to our test environments to specific times during the day in order to not disturb our testers
We have a manual intervention step in all our deployment processes:
From the log we can see that the server task ID = “ServerTasks-432273”
The raw log for this deploy:
We use the Octopus Client API to submit the deployments:
foreach ($interupt in $repository.Interruptions.List().Items)
{
if ($interupt.TaskId -eq “ServerTasks-432273”)
{
Write-Host “This is the one”
}
if ( ($interupt.Title -eq “DeployTimeIntervention” -or $interupt.Title -eq “DevOps.DeployTimeIntervention”) -and $interupt.IsPending) #does not catch ServerTasks-432273
{
$taskId = $interupt.TaskId
$file = $date_time.ToString(“yyyy-MM-dd”) #Write-Output “Starting server task: $taskId”
Add-Content “.$file.log” “Starting server task: $taskId”
$interupt.Form.Values[“Result”] = “Proceed”;
$octoClient.Post($interupt.Link(“Submit”),$interupt.Form.Values, $null);
}
}
This has worked well for about a year but lately some deployments are not beeing processed.
I also posted this question which might be related:
When this issue occurs, would you be able to generate and attach an extract of all interruptions using http://<serverURL>/api/Spaces-1/interruptions?skip=0&take=2147483647
It would be interesting to see if the problem is that it doesn’t appear in the list at all, or if something is causing the title or state to be different to what your script expects.
Could you also provide the Task ID too when you do this?
I have attached the raw log. As you can see from the log the deployment was manually resubmitted. The GUI doesn’t seem to work directly with the Interuptions object?
Would a script set to run for just a Test environment that checks the time against an allowed time be an approach works for you?
For instance, you could have something like the below:
$workDayStartHour = $OctopusParameters["WorkingHoursCheck.StartTime.Hour"]
$workDayStartMinute = $OctopusParameters["WorkingHoursCheck.StartTime.Minute"]
$workDayEndHour = $OctopusParameters["WorkingHoursCheck.EndTime.Hour"]
$workDayEndMinute = $OctopusParameters["WorkingHoursCheck.EndTime.Minute"]
Write-Host "Working Day Start Hour $workDayStartHour"
Write-Host "Working Day Start Minute $workDayStartMinute"
Write-Host "Working Day End Hour $workDayEndHour"
Write-host "Working Day End Minute $workDayEndMinute"
$workDayStart = Get-Date -Hour $workDayStartHour -Minute $workDayStartMinute
Write-Host "The working day is set to start at $workDayStart"
$workDayEnd = Get-Date -Hour $workDayEndHour -Minute $workDayEndMinute
Write-Host "The working day is set to end at $workDayEnd"
$currentDate = Get-Date
Write-Host "The current time on the server is $currentDate"
if ($currentDate -lt $workDayStart)
{
Write-Host "No manual intervention required, the current time is $currentDate which is less than $workDayStart"
$manualInterventionRequired = $false
}
elseif ($currentDate -gt $workDayEnd)
{
Write-Host "No manual intervention required, the current time is $currentDate which is greater than $workDayEnd"
$manualInterventionRequired = $false
}
else {
Write-Host "Attempting to deploy during the work day, manual intervention required"
$manualInterventionRequired = $true
}
Write-Host "Manual Intervention Is Required: $manualInterventionRequired"
Set-OctopusVariable -name "ManualInterventionRequired" -value $manualInterventionRequired
From there, you could then specify the hours allowed as a library or project variable like below:
Another approach would be to use Scheduled Triggers with no manual intervention to run at a set time, which is in the allowed time frame? You could set this to trigger a deployment to test at X time daily, Days per week, Days per month, and as a CRON expression as below: