diff options
author | Juha Karjalainen <juha.karjalainen@qt.io> | 2019-01-23 16:13:35 +0200 |
---|---|---|
committer | Aapo Keskimolo <aapo.keskimolo@qt.io> | 2019-02-14 15:22:56 +0000 |
commit | ce91433364990032214884bbceb723a60a9756b1 (patch) | |
tree | a09b2e2b570d340cbc6f39068ab29c7181fe9019 /coin/provisioning/common/windows/helpers.ps1 | |
parent | ab438507e9ce6d6a4c823b76929c13cc6d9a6072 (diff) |
Fix failing to disable windows update service
Sometimes when trying to stop windows update service it fails.
Will now retry disabling wuauserv
Task-number: QTQAINFRA-2632
Change-Id: I5b6bf40aa15bb1f5225dc51e2f7212a01a13e9a6
Reviewed-by: Heikki Halmet <heikki.halmet@qt.io>
Diffstat (limited to 'coin/provisioning/common/windows/helpers.ps1')
-rw-r--r-- | coin/provisioning/common/windows/helpers.ps1 | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index 76ad4867..9cd8567e 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -159,3 +159,35 @@ function IsProxyEnabled { function Get-Proxy { return (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').proxyServer } + +function Retry{ + <# + usage: + Retry{CODE} + Retry{CODE} <num of retries> <delay_s> + #delay is in seconds + #> + Param( + [Parameter(mandatory=$true)] + [scriptblock]$command, + [int][ValidateRange(1, 20)]$retry = 5, + [int][ValidateRange(1, 60)]$delay_s = 5 + ) + $success=$false + $retry_count=0 + do{ + try { + Invoke-Command -ScriptBlock $command + $success=$true + } + catch { + $retry_count++ + Write-Host "Error: $_, try: $retry_count, retrying in $delay_s seconds" + Start-Sleep -Seconds $delay_s + } + } until ($success -or $retry+1 -le $retry_count) + + if (-not $success) { + Throw("Failed to run command successfully in $retry_count tries") + } +} |