[Windows] Add pause after Windows Update (#4641)

This commit is contained in:
Aleksandr Chebotov
2021-12-02 10:56:43 +03:00
committed by GitHub
parent d0f20ddfa3
commit c50afe27cd
4 changed files with 22 additions and 5 deletions

View File

@@ -519,7 +519,7 @@ function Get-WindowsUpdatesHistory {
43 { 43 {
$status = "InProgress" $status = "InProgress"
$title = $event.Properties[0].Value $title = $event.Properties[0].Value
break break
} }
} }
@@ -538,7 +538,7 @@ function Invoke-SBWithRetry {
param ( param (
[scriptblock] $Command, [scriptblock] $Command,
[int] $RetryCount = 10, [int] $RetryCount = 10,
[int] $TimeoutInSecs = 5 [int] $RetryIntervalSeconds = 5
) )
while ($RetryCount -gt 0) { while ($RetryCount -gt 0) {
@@ -547,15 +547,15 @@ function Invoke-SBWithRetry {
return return
} }
catch { catch {
Write-Host "There is an error encounterd:`n $_" Write-Host "There is an error encountered:`n $_"
$RetryCount-- $RetryCount--
if ($RetryCount -eq 0) { if ($RetryCount -eq 0) {
exit 1 exit 1
} }
Write-Host "Waiting $TimeoutInSecs seconds before retrying. Retries left: $RetryCount" Write-Host "Waiting $RetryIntervalSeconds seconds before retrying. Retries left: $RetryCount"
Start-Sleep -Seconds $TimeoutInSecs Start-Sleep -Seconds $RetryIntervalSeconds
} }
} }
} }

View File

@@ -0,0 +1,12 @@
################################################################################
## File: Wait-WindowsUpdatesForInstall.ps1
## Desc: Wait for installation windows updates to complete
################################################################################
Invoke-SBWithRetry -RetryCount 10 -RetryIntervalSeconds 120 -Command {
$inProgress = Get-WindowsUpdatesHistory | Where-Object Status -eq "InProgress"
if ( $inProgress ) {
$title = $inProgress.Title -join "`n"
throw "InProgress: $title"
}
}

View File

@@ -274,6 +274,7 @@
"type": "powershell", "type": "powershell",
"pause_before": "2m", "pause_before": "2m",
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Wait-WindowsUpdatesForInstall.ps1",
"{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1" "{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1"
] ]
}, },

View File

@@ -251,11 +251,15 @@
}, },
{ {
"type": "windows-restart", "type": "windows-restart",
"check_registry": true,
"restart_check_command": "powershell -command \"& {if ((-not (Get-Process TiWorker.exe -ErrorAction SilentlyContinue)) -and (-not [System.Environment]::HasShutdownStarted) ) { Write-Output 'Restart complete' }}\"",
"restart_timeout": "30m" "restart_timeout": "30m"
}, },
{ {
"type": "powershell", "type": "powershell",
"pause_before": "2m",
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Wait-WindowsUpdatesForInstall.ps1",
"{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1" "{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1"
] ]
}, },