From c5e468893d9843a69725cf78b8263ab8e2aadcc5 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Mon, 19 Oct 2020 13:28:53 +0300 Subject: [PATCH] [macOS] Add retry for toolcache assets (#1798) * Add retry for toolset manifest downloading * Add common helper * Minor fix * Fix helper module path * Fix helper module path --- images/macos/helpers/Common.Helpers.psm1 | 17 +++++++++++++---- images/macos/provision/core/toolset.ps1 | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/images/macos/helpers/Common.Helpers.psm1 b/images/macos/helpers/Common.Helpers.psm1 index aa2ffdc5c..dd8a2184b 100644 --- a/images/macos/helpers/Common.Helpers.psm1 +++ b/images/macos/helpers/Common.Helpers.psm1 @@ -24,7 +24,7 @@ function Get-EnvironmentVariable($variable) { } # Returns the object with information about current OS -# It can be used for OS-specific tests +# It can be used for OS-specific tests function Get-OSVersion { $osVersion = [Environment]::OSVersion return [PSCustomObject]@{ @@ -36,7 +36,7 @@ function Get-OSVersion { IsBigSur = $osVersion.Version.Major -eq 20 IsLessThanCatalina = $osVersion.Version.Major -lt 19 IsLessThanBigSur = $osVersion.Version.Major -lt 20 - IsHigherThanMojave = $osVersion.Version.Major -gt 18 + IsHigherThanMojave = $osVersion.Version.Major -gt 18 } } @@ -63,7 +63,7 @@ function Get-ToolsetValue { $jsonNode = Get-Content -Raw $toolsetPath | ConvertFrom-Json $pathParts = $KeyPath.Split(".") - # try to walk through all arguments consequentially to resolve specific json node + # try to walk through all arguments consequentially to resolve specific json node $pathParts | ForEach-Object { $jsonNode = $jsonNode.$_ } @@ -73,4 +73,13 @@ function Get-ToolsetValue { function Get-ToolcachePackages { $toolcachePath = Join-Path $env:HOME "image-generation" "toolcache.json" return Get-Content -Raw $toolcachePath | ConvertFrom-Json -} \ No newline at end of file +} + +function Invoke-RestMethodWithRetry { + param ( + [Parameter()] + [string] + $Url + ) + Invoke-RestMethod $Url -MaximumRetryCount 10 -RetryIntervalSec 30 +} diff --git a/images/macos/provision/core/toolset.ps1 b/images/macos/provision/core/toolset.ps1 index bc016c4b3..9238b9ff4 100644 --- a/images/macos/provision/core/toolset.ps1 +++ b/images/macos/provision/core/toolset.ps1 @@ -4,6 +4,8 @@ ## Desc: Install toolset ################################################################################ +Import-Module "~/image-generation/helpers/Common.Helpers.psm1" + Function Get-ToolcacheFromToolset { $toolsetPath = Join-Path $env:HOME "image-generation" "toolset.json" $toolsetJson = Get-Content -Raw $toolsetPath | ConvertFrom-Json @@ -38,7 +40,7 @@ $tools = Get-ToolcacheFromToolset | Where-Object {$ToolsToInstall -contains $_. foreach ($tool in $tools) { # Get versions manifest for current tool - $assets = Invoke-RestMethod $tool.url + $assets = Invoke-RestMethodWithRetry -Url $tool.url # Get github release asset for each version foreach ($version in $tool.versions) {