Skip to content

Commit f89342c

Browse files
Implement retry logic for module installation in main.ps1 to enhance reliability
1 parent 134c719 commit f89342c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scripts/main.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ param()
55

66
LogGroup 'Init - Setup prerequisites' {
77
'Markdown' | ForEach-Object {
8-
Write-Output "Installing module: $_"
9-
Install-PSResource -Name $_ -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
10-
Import-Module -Name $_
8+
$name = $_
9+
Write-Output "Installing module: $name"
10+
$retryCount = 5
11+
$retryDelay = 10
12+
for ($i = 0; $i -lt $retryCount; $i++) {
13+
try {
14+
Install-PSResource -Name $name -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
15+
break
16+
} catch {
17+
Write-Warning "Installation of $name failed with error: $_"
18+
if ($i -eq $retryCount - 1) {
19+
throw
20+
}
21+
Write-Warning "Retrying in $retryDelay seconds..."
22+
Start-Sleep -Seconds $retryDelay
23+
}
24+
}
25+
Import-Module -Name $name
1126
}
1227
Import-Module "$PSScriptRoot/Helpers.psm1"
1328
}

0 commit comments

Comments
 (0)