@@ -62,8 +62,24 @@ Describe 'Organizations' {
6262 if ($staleOrg -and $staleOrg.Name ) {
6363 Write-Host " Stale org [$orgName ] found from previous run attempt. Removing..."
6464 try {
65- $null = Install-GitHubApp - Enterprise $owner - Organization $orgName `
66- - ClientID $installationContext.ClientID - RepositorySelection ' all' - ErrorAction Stop
65+ # Retry Install-GitHubApp: the enterprise apps endpoint can return 404
66+ # for a short time after the org was originally created.
67+ $maxAttempts = 5
68+ $retryDelay = 3
69+ for ($retryAttempt = 1 ; $retryAttempt -le $maxAttempts ; $retryAttempt ++ ) {
70+ try {
71+ $null = Install-GitHubApp - Enterprise $owner - Organization $orgName `
72+ - ClientID $installationContext.ClientID - RepositorySelection ' all' - ErrorAction Stop
73+ break
74+ } catch {
75+ if ($retryAttempt -lt $maxAttempts ) {
76+ Write-Host " Install-GitHubApp attempt $retryAttempt /$maxAttempts failed: $ ( $_.Exception.Message ) . Retrying in ${retryDelay} s..."
77+ Start-Sleep - Seconds $retryDelay
78+ } else {
79+ throw
80+ }
81+ }
82+ }
6783 $cleanupOrgContext = Connect-GitHubApp - Organization $orgName - Context $context - PassThru - Silent
6884 Remove-GitHubOrganization - Name $orgName - Confirm:$false - Context $cleanupOrgContext
6985 Write-Host " Stale org [$orgName ] removed."
@@ -178,7 +194,25 @@ Describe 'Organizations' {
178194 }
179195
180196 It ' Install-GitHubApp - Installs a GitHub App to an organization' - Skip:($OwnerType -ne ' enterprise' ) {
181- $installation = Install-GitHubApp - Enterprise $owner - Organization $orgName - ClientID $installationContext.ClientID - RepositorySelection ' all'
197+ # Retry: the enterprise apps endpoint can return 404 transiently right after
198+ # New-GitHubOrganization, before the new org has propagated.
199+ $maxAttempts = 5
200+ $retryDelay = 3
201+ $installation = $null
202+ for ($retryAttempt = 1 ; $retryAttempt -le $maxAttempts ; $retryAttempt ++ ) {
203+ try {
204+ $installation = Install-GitHubApp - Enterprise $owner - Organization $orgName `
205+ - ClientID $installationContext.ClientID - RepositorySelection ' all' - ErrorAction Stop
206+ break
207+ } catch {
208+ if ($retryAttempt -lt $maxAttempts ) {
209+ Write-Host " Install-GitHubApp attempt $retryAttempt /$maxAttempts failed: $ ( $_.Exception.Message ) . Retrying in ${retryDelay} s..."
210+ Start-Sleep - Seconds $retryDelay
211+ } else {
212+ throw
213+ }
214+ }
215+ }
182216 LogGroup ' Installed App' {
183217 Write-Host ($installation | Select-Object * | Out-String )
184218 }
0 commit comments