Skip to content

Commit 5638880

Browse files
author
John Luo
authored
Update helix installation retry logic (#30022)
* Update helix installation retry logic Restart SDK and runtime installation upon retry
1 parent b338239 commit 5638880

File tree

2 files changed

+52
-29
lines changed

2 files changed

+52
-29
lines changed

.azure/pipelines/helix-matrix.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# We only want to run full helix matrix on main
2-
pr: none
2+
pr:
3+
autoCancel: true
4+
branches:
5+
include:
6+
- '*'
37
trigger: none
48
schedules:
59
# Cron timezone is UTC.

eng/helix/content/runtests.ps1

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,72 @@ param(
1111
[string]$FeedCred
1212
)
1313

14-
$currentDirectory = Get-Location
15-
$random = Get-Random -Maximum 1024
16-
17-
$env:DOTNET_HOME = Join-Path $currentDirectory "sdk$random"
18-
$env:DOTNET_ROOT = Join-Path $env:DOTNET_HOME $Arch
1914
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
2015
$env:DOTNET_MULTILEVEL_LOOKUP = 0
21-
$env:DOTNET_CLI_HOME = Join-Path $currentDirectory "home$random"
22-
$env:PATH = "$env:DOTNET_ROOT;$env:PATH;$env:HELIX_CORRELATION_PAYLOAD\node\bin"
2316

24-
Write-Host "Set PATH to: $env:PATH"
17+
$currentDirectory = Get-Location
18+
$envPath = "$env:PATH;$env:HELIX_CORRELATION_PAYLOAD\node\bin"
2519

2620
function InvokeInstallDotnet([string]$command) {
21+
Write-Host "InstallDotNet $command"
22+
23+
$timeoutSeconds = 180
24+
$proc = Start-Process -filePath powershell.exe -ArgumentList "-noLogo -NoProfile -ExecutionPolicy unrestricted -command `"$command`"" -NoNewWindow -PassThru
25+
26+
$proc | Wait-Process -Timeout $timeoutSeconds
27+
$exitCode = $proc.ExitCode
28+
29+
if ($exitCode -eq 0) {
30+
Write-Host "InstallDotNet $command completed successfully"
31+
return $true
32+
}
33+
elseif ([string]::IsNullOrWhiteSpace($exitCode)) {
34+
Write-Warning "InstallDotNet $command timed out after $timeoutSeconds seconds"
35+
}
36+
else {
37+
Write-Warning "InstallDotNet $command failed with exit code $exitCode"
38+
}
39+
40+
$proc | Stop-Process -Force
41+
42+
return $false
43+
}
44+
45+
function InstallDotnetSDKAndRuntime([string]$Feed, [string]$FeedCredParam) {
2746
foreach ($i in 1..5) {
28-
Write-Host "InstallDotNet $command"
47+
$random = Get-Random -Maximum 1024
48+
$env:DOTNET_HOME = Join-Path $currentDirectory "sdk$random"
49+
$env:DOTNET_ROOT = Join-Path $env:DOTNET_HOME $Arch
50+
$env:DOTNET_CLI_HOME = Join-Path $currentDirectory "home$random"
51+
$env:PATH = "$env:DOTNET_ROOT;$envPath"
2952

30-
$timeoutSeconds = 120
31-
$proc = Start-Process -filePath powershell.exe -ArgumentList "-noLogo -NoProfile -ExecutionPolicy unrestricted -command `"$command`"" -NoNewWindow -PassThru
53+
Write-Host "Set PATH to: $env:PATH"
3254

33-
$proc | Wait-Process -Timeout $timeoutSeconds
34-
$exitCode = $proc.ExitCode
55+
$success = InvokeInstallDotnet ". eng\common\tools.ps1; InstallDotNet $env:DOTNET_ROOT $SdkVersion $Arch `'`' `$true `'$Feed`' `'$FeedCredParam`' `$true"
3556

36-
if ($exitCode -eq 0) {
37-
Write-Host "InstallDotNet $command completed successfully"
38-
return
57+
if (!$success) {
58+
Write-Host "Retrying..."
59+
continue
3960
}
4061

41-
if ([string]::IsNullOrWhiteSpace($exitCode)) {
42-
Write-Warning "InstallDotNet $command timed out after $timeoutSeconds seconds retrying..."
43-
}
44-
else {
45-
Write-Warning "InstallDotNet $command failed with exit code $exitCode retrying..."
62+
$success = InvokeInstallDotnet ". eng\common\tools.ps1; InstallDotNet $env:DOTNET_ROOT $RuntimeVersion $Arch dotnet `$true `'$Feed`' `'$FeedCredParam`' `$true"
63+
64+
if (!$success) {
65+
Write-Host "Retrying..."
66+
continue
4667
}
4768

48-
$proc | Stop-Process -Force
69+
return
4970
}
5071

51-
Write-Warning "InstallDotNet $command exceeded retry limit"
72+
Write-Error "InstallDotNet $command exceeded retry limit"
5273
exit 1
5374
}
5475

55-
if ($FeedCred -eq $null) {
56-
InvokeInstallDotnet(". eng\common\tools.ps1; InstallDotNet $env:DOTNET_ROOT $SdkVersion $Arch `'`' `$true `'`' `'`' `$true")
57-
InvokeInstallDotnet(". eng\common\tools.ps1; InstallDotNet $env:DOTNET_ROOT $RuntimeVersion $Arch dotnet `$true `'`' `'`' `$true")
76+
if ([string]::IsNullOrEmpty($FeedCred)) {
77+
InstallDotnetSDKAndRuntime
5878
} else {
59-
InvokeInstallDotnet(". eng\common\tools.ps1; InstallDotNet $env:DOTNET_ROOT $SdkVersion $Arch `'`' `$true https://dotnetclimsrc.blob.core.windows.net/dotnet $FeedCred `$true")
60-
InvokeInstallDotnet(". eng\common\tools.ps1; InstallDotNet $env:DOTNET_ROOT $RuntimeVersion $Arch dotnet `$true https://dotnetclimsrc.blob.core.windows.net/dotnet $FeedCred `$true")
79+
InstallDotnetSDKAndRuntime "https://dotnetclimsrc.blob.core.windows.net/dotnet" $FeedCred
6180
}
6281

6382
Write-Host "Restore: dotnet restore RunTests\RunTests.csproj --ignore-failed-sources"

0 commit comments

Comments
 (0)