@@ -215,7 +215,7 @@ function Invoke-LiveTestCommand {
215
215
}
216
216
217
217
function Invoke-LiveTestScenario {
218
- [CmdletBinding ()]
218
+ [CmdletBinding (DefaultParameterSetName = " HasDefaultResourceGroup " )]
219
219
[OutputType ([bool ])]
220
220
param (
221
221
[Parameter (Mandatory , Position = 0 )]
@@ -226,10 +226,13 @@ function Invoke-LiveTestScenario {
226
226
[ValidateNotNullOrEmpty ()]
227
227
[string ] $Description ,
228
228
229
- [Parameter ()]
229
+ [Parameter (ParameterSetName = " HasDefaulResourceGroup " )]
230
230
[ValidateNotNullOrEmpty ()]
231
231
[string ] $ResourceGroupLocation ,
232
232
233
+ [Parameter (ParameterSetName = " HasNoDefaultResourceGroup" )]
234
+ [switch ] $NoResourceGroup ,
235
+
233
236
[Parameter (Mandatory )]
234
237
[ValidateNotNullOrEmpty ()]
235
238
[scriptblock ] $ScenarioScript
@@ -256,32 +259,34 @@ function Invoke-LiveTestScenario {
256
259
Errors = " "
257
260
}
258
261
259
- $snrResourceGroupName = New-LiveTestResourceGroupName
260
- $snrResourceGroupLocation = " westus"
261
- if ($PSBoundParameters.ContainsKey (" ResourceGroupLocation" )) {
262
- $snrResourceGroupLocation = $ResourceGroupLocation
263
- }
262
+ if (! $NoResourceGroup.IsPresent ) {
263
+ $snrResourceGroupName = New-LiveTestResourceGroupName
264
+ $snrResourceGroupLocation = " westus"
265
+ if ($PSBoundParameters.ContainsKey (" ResourceGroupLocation" )) {
266
+ $snrResourceGroupLocation = $ResourceGroupLocation
267
+ }
264
268
265
- Write-Host " ##[section]Start to create a resource group." - ForegroundColor Green
266
- Write-Host " ##[section]Resource group name: $snrResourceGroupName " - ForegroundColor Green
267
- Write-Host " ##[section]Resource group location: $snrResourceGroupLocation " - ForegroundColor Green
269
+ Write-Host " ##[section]Start to create a resource group." - ForegroundColor Green
270
+ Write-Host " ##[section]Resource group name: $snrResourceGroupName " - ForegroundColor Green
271
+ Write-Host " ##[section]Resource group location: $snrResourceGroupLocation " - ForegroundColor Green
268
272
269
- $snrResourceGroup = New-LiveTestResourceGroup - Name $snrResourceGroupName - Location $snrResourceGroupLocation
273
+ $snrResourceGroup = New-LiveTestResourceGroup - Name $snrResourceGroupName - Location $snrResourceGroupLocation
270
274
271
- Write-Host " ##[section]Successfully created the resource group." - ForegroundColor Green
275
+ Write-Host " ##[section]Successfully created the resource group." - ForegroundColor Green
276
+ }
272
277
273
278
$snrRetryCount = 0
274
279
$snrRetryErrors = @ ()
275
280
276
281
do {
277
282
try {
283
+ $sPrefs = @ ([psvariable ]::new(" ErrorActionPreference" , " Stop" ), [psvariable ]::new(" ConfirmPreference" , " None" ))
278
284
if ($snrRetryCount -eq $script :ScenarioMaxRetryCount ) {
279
- $ScenarioScript.InvokeWithContext ($null , @ ([psvariable ]::new(" ErrorActionPreference" , " Stop" ), [psvariable ]::new(" ConfirmPreference" , " None" ), [psvariable ]::new(" DebugPreference" , " Continue" )), $snrResourceGroup )
280
- }
281
- else {
282
- $ScenarioScript.InvokeWithContext ($null , @ ([psvariable ]::new(" ErrorActionPreference" , " Stop" ), [psvariable ]::new(" ConfirmPreference" , " None" )), $snrResourceGroup )
285
+ $prefs += [psvariable ]::new(" DebugPreference" , " Continue" )
283
286
}
284
287
288
+ $ScenarioScript.InvokeWithContext ($null , $prefs , $snrResourceGroup )
289
+
285
290
Write-Host " ##[section]Successfully executed the live scenario `" $Name `" ." - ForegroundColor Green
286
291
break
287
292
}
@@ -346,7 +351,10 @@ function Invoke-LiveTestScenario {
346
351
$snrCsvData.Errors = ConvertToLiveTestJsonErrors - Errors $snrErrorMessage
347
352
}
348
353
finally {
349
- if ($null -ne $snrResourceGroup ) {
354
+ $snrCsvData.EndDateTime = (Get-Date ).ToUniversalTime().ToString(" yyyy-MM-ddTHH:mm:ss" )
355
+ $snrCsvData | Export-Csv - LiteralPath $script :LiveTestRawCsvFile - Encoding utf8 - NoTypeInformation - Append
356
+
357
+ if (! $NoResourceGroup.IsPresent -and $null -ne $snrResourceGroup ) {
350
358
try {
351
359
Write-Host " ##[section]Start to clean up the resource group `" $snrResourceGroupName `" ." - ForegroundColor Green
352
360
Clear-LiveTestResources - Name $snrResourceGroupName
@@ -355,8 +363,6 @@ function Invoke-LiveTestScenario {
355
363
# Ignore exception for clean up
356
364
}
357
365
}
358
- $snrCsvData.EndDateTime = (Get-Date ).ToUniversalTime().ToString(" yyyy-MM-ddTHH:mm:ss" )
359
- $snrCsvData | Export-Csv - LiteralPath $script :LiveTestRawCsvFile - Encoding utf8 - NoTypeInformation - Append
360
366
361
367
Write-Host " ##[endgroup]"
362
368
}
0 commit comments