Skip to content

Commit 25b8d49

Browse files
Enhance module installation process with retry logic and improved error handling
1 parent caad0c6 commit 25b8d49

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

scripts/main.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,24 @@ param()
88
$PSStyle.OutputRendering = 'Ansi'
99

1010
'platyPS' | ForEach-Object {
11-
Install-PSResource -Name $_ -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
12-
Import-Module -Name $_
11+
$name = $_
12+
Write-Output "Installing module: $name"
13+
$retryCount = 5
14+
$retryDelay = 10
15+
for ($i = 0; $i -lt $retryCount; $i++) {
16+
try {
17+
Install-PSResource -Name $name -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
18+
break
19+
} catch {
20+
Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_"
21+
if ($i -eq $retryCount - 1) {
22+
throw
23+
}
24+
Write-Warning "Retrying in $retryDelay seconds..."
25+
Start-Sleep -Seconds $retryDelay
26+
}
27+
}
28+
Import-Module -Name $name
1329
}
1430

1531
$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative

0 commit comments

Comments
 (0)