Skip to content

Commit 01ea27e

Browse files
committed
Retry installing Visual Studio Build Tools on failure
We've seen occasional failures to install the Visual Studio Build Tools due to flakey responses from the server. Attempt to make this script more robust by adding a retry with exponential backoff, attempting up to 10 times before eventually giving up. This adds the same logic to both the VSB and Swift toolchain downloads.
1 parent 457d77c commit 01ea27e

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

.github/workflows/scripts/windows/install-vsb.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,30 @@ $VSB_SHA256='C792BDB0FD46155DE19955269CAC85D52C4C63C23DB2CF43D96B9390146F9390'
1414
Set-Variable ErrorActionPreference Stop
1515
Set-Variable ProgressPreference SilentlyContinue
1616
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${VSB})
17-
Invoke-WebRequest -Uri $VSB -OutFile $env:TEMP\vs_buildtools.exe
18-
Write-Host 'SUCCESS'
17+
$MaxRetries = 10
18+
$BaseDelay = 1
19+
$Attempt = 0
20+
$Success = $false
21+
22+
while (-not $Success -and $Attempt -lt $MaxRetries) {
23+
$Attempt++
24+
try {
25+
Invoke-WebRequest -Uri $VSB -OutFile $env:TEMP\vs_buildtools.exe
26+
$Success = $true
27+
Write-Host 'SUCCESS'
28+
}
29+
catch {
30+
if ($Attempt -eq $MaxRetries) {
31+
Write-Host "FAILED after $MaxRetries attempts: $($_.Exception.Message)"
32+
exit 1
33+
}
34+
35+
# Calculate exponential backoff delay (2^attempt * base delay)
36+
$Delay = $BaseDelay * [Math]::Pow(2, $Attempt - 1)
37+
Write-Host "Attempt $Attempt failed, retrying in $Delay seconds..."
38+
Start-Sleep -Seconds $Delay
39+
}
40+
}
1941
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $VSB_SHA256)
2042
$Hash = Get-FileHash $env:TEMP\vs_buildtools.exe -Algorithm sha256
2143
if ($Hash.Hash -eq $VSB_SHA256) {

.github/workflows/scripts/windows/swift/install-swift.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,30 @@ function Install-Swift {
1717
Set-Variable ErrorActionPreference Stop
1818
Set-Variable ProgressPreference SilentlyContinue
1919
Write-Host -NoNewLine ('Downloading {0} ... ' -f $url)
20-
Invoke-WebRequest -Uri $url -OutFile installer.exe
21-
Write-Host 'SUCCESS'
20+
$MaxRetries = 10
21+
$BaseDelay = 1
22+
$Attempt = 0
23+
$Success = $false
24+
25+
while (-not $Success -and $Attempt -lt $MaxRetries) {
26+
$Attempt++
27+
try {
28+
Invoke-WebRequest -Uri $url -OutFile installer.exe
29+
$Success = $true
30+
Write-Host 'SUCCESS'
31+
}
32+
catch {
33+
if ($Attempt -eq $MaxRetries) {
34+
Write-Host "FAILED after $MaxRetries attempts: $($_.Exception.Message)"
35+
exit 1
36+
}
37+
38+
# Calculate exponential backoff delay (2^attempt * base delay)
39+
$Delay = $BaseDelay * [Math]::Pow(2, $Attempt - 1)
40+
Write-Host "Attempt $Attempt failed, retrying in $Delay seconds..."
41+
Start-Sleep -Seconds $Delay
42+
}
43+
}
2244
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $Sha256)
2345
$Hash = Get-FileHash installer.exe -Algorithm sha256
2446
if ($Hash.Hash -eq $Sha256 -or $Sha256 -eq "") {

0 commit comments

Comments
 (0)