@@ -62,22 +62,25 @@ Function New-WinGetSource
62
62
. PARAMETER ShowConnectionInstructions
63
63
[Optional] If specified, the instructions for connecting to the Windows Package Manager REST source. (Default: False)
64
64
65
+ . PARAMETER MaxRetryCount
66
+ [Optional] Max ARM template deployment retry count upon failure. (Default: 5)
67
+
65
68
. EXAMPLE
66
- New-WinGetSource -Name "contosorestsource"
69
+ New-WinGetSource -Name "contosorestsource" -InformationAction Continue -Verbose
67
70
68
71
Creates the Windows Package Manager REST source in Azure with resources named "contosorestsource" in the westus region of
69
72
Azure with the basic level performance.
70
73
71
74
. EXAMPLE
72
- New-WinGetSource -Name "contosorestsource" -ResourceGroup "WinGet" -SubscriptionName "Visual Studio Subscription" -Region "westus" -ParameterOutput "C:\WinGet" -ImplementationPerformance "Basic" -ShowConnectionInformation
75
+ New-WinGetSource -Name "contosorestsource" -ResourceGroup "WinGet" -SubscriptionName "Visual Studio Subscription" -Region "westus" -ParameterOutput "C:\WinGet" -ImplementationPerformance "Basic" -ShowConnectionInformation -InformationAction Continue -Verbose
73
76
74
77
Creates the Windows Package Manager REST source in Azure with resources named "contosorestsource" in the westus region of
75
78
Azure with the basic level performance in the "Visual Studio Subscription" Subscription. Displays the required command
76
79
to connect the WinGet client to the new REST source after the REST source has been created.
77
80
78
81
#>
79
82
PARAM (
80
- [Parameter (Position = 0 , Mandatory = $true )] [string ]$Name ,
83
+ [Parameter (Position = 0 , Mandatory = $true )] [string ]$Name ,
81
84
[Parameter (Mandatory = $false )] [string ]$ResourceGroup = " WinGetRestSource" ,
82
85
[Parameter (Mandatory = $false )] [string ]$SubscriptionName = " " ,
83
86
[Parameter (Mandatory = $false )] [string ]$Region = " westus" ,
@@ -93,7 +96,8 @@ Function New-WinGetSource
93
96
[Parameter ()] [switch ]$CreateNewMicrosoftEntraIdAppRegistration ,
94
97
[Parameter (Mandatory = $false )] [string ]$MicrosoftEntraIdResource = " " ,
95
98
[Parameter (Mandatory = $false )] [string ]$MicrosoftEntraIdResourceScope = " " ,
96
- [Parameter ()] [switch ]$ShowConnectionInstructions
99
+ [Parameter ()] [switch ]$ShowConnectionInstructions ,
100
+ [Parameter (Mandatory = $false )] [int ]$MaxRetryCount = 5
97
101
)
98
102
99
103
if ($ImplementationPerformance -eq " Developer" ) {
@@ -106,11 +110,11 @@ Function New-WinGetSource
106
110
107
111
# ##############################
108
112
# # Check input paths
109
- if (! $ (Test-Path - Path $TemplateFolderPath )) {
113
+ if (! $ (Test-Path - Path $TemplateFolderPath )) {
110
114
Write-Error " REST Source Function Code is missing in specified path ($TemplateFolderPath )"
111
115
return $false
112
116
}
113
- if (! $ (Test-Path - Path $RestSourcePath )) {
117
+ if (! $ (Test-Path - Path $RestSourcePath )) {
114
118
Write-Error " REST Source Function Code is missing in specified path ($RestSourcePath )"
115
119
return $false
116
120
}
@@ -125,7 +129,7 @@ Function New-WinGetSource
125
129
# ##############################
126
130
# # Create folder for the Parameter output path
127
131
$Result = New-Item - ItemType Directory - Path $ParameterOutputPath - Force
128
- if ($Result ) {
132
+ if ($Result ) {
129
133
Write-Verbose - Message " Created Directory to contain the ARM Parameter files ($ ( $Result.FullName ) )."
130
134
}
131
135
else {
@@ -135,9 +139,9 @@ Function New-WinGetSource
135
139
136
140
# ##############################
137
141
# # Connects to Azure, if not already connected.
138
- Write-Information " Testing connection to Azure ."
142
+ Write-Information " Validating connection to azure, will attempt to connect if not already connected ."
139
143
$Result = Connect-ToAzure - SubscriptionName $SubscriptionName
140
- if (! ($Result )) {
144
+ if (! ($Result )) {
141
145
Write-Error " Failed to connect to Azure. Please run Connect-AzAccount to connect to Azure, or re-run the cmdlet and enter your credentials."
142
146
return $false
143
147
}
@@ -173,7 +177,8 @@ Function New-WinGetSource
173
177
return $false
174
178
}
175
179
176
- # ### Verifies ARM Parameters are correct
180
+ # ##############################
181
+ # # Verifies ARM Parameters are correct. If any failed, the return results will contain failed objects. Otherwise, success.
177
182
$Result = Test-ARMTemplates - ARMObjects $ARMObjects - ResourceGroup $ResourceGroup
178
183
if ($Result ){
179
184
$ErrReturnObject = @ {
@@ -188,11 +193,25 @@ Function New-WinGetSource
188
193
189
194
# ##############################
190
195
# # Creates Azure Objects with ARM Templates and Parameters
191
- $Result = New-ARMObjects - ARMObjects $ARMObjects - RestSourcePath $RestSourcePath - ResourceGroup $ResourceGroup
192
- if (! $Result ) {
193
- Write-Error " Failed to create Azure resources for WinGet rest source"
194
- return $false
195
- }
196
+ $Attempt = 0
197
+ $Retry = $false
198
+ do {
199
+ $Attempt ++
200
+ $Retry = $false
201
+
202
+ $Result = New-ARMObjects - ARMObjects ([ref ]$ARMObjects ) - RestSourcePath $RestSourcePath - ResourceGroup $ResourceGroup
203
+ if (! $Result ) {
204
+ if ($Attempt -lt $MaxRetryCount ) {
205
+ $Retry = $true
206
+ Write-Verbose " Retrying deployment after 15 seconds."
207
+ Start-Sleep - Seconds 15
208
+ }
209
+ else {
210
+ Write-Error " Failed to create Azure resources for WinGet rest source."
211
+ return $false
212
+ }
213
+ }
214
+ } while ($Retry )
196
215
197
216
# ##############################
198
217
# # Shows how to connect local Windows Package Manager Client to newly created REST source
@@ -203,7 +222,7 @@ Function New-WinGetSource
203
222
# # Post script Run Informational:
204
223
# ### Instructions on how to add the REST source to your Windows Package Manager Client
205
224
Write-Information - MessageData " Use the following command to register the new REST source with your Windows Package Manager Client:" - InformationAction Continue
206
- Write-Information - MessageData " winget source add -n "" restsource "" -a "" $ApiManagementURL /winget/"" -t "" Microsoft.Rest"" " - InformationAction Continue
225
+ Write-Information - MessageData " winget source add -n "" $Name "" -a "" $ApiManagementURL /winget/"" -t "" Microsoft.Rest"" " - InformationAction Continue
207
226
208
227
# ### For more information about how to use the solution, visit the aka.ms link.
209
228
Write-Information - MessageData " `n For more information on the Windows Package Manager Client, go to: https://aka.ms/winget-command-help`n " - InformationAction Continue
0 commit comments