@@ -16,8 +16,8 @@ param (
1616 [ValidatePattern (' ^[-a-zA-Z0-9\.\(\)_]{0,80}(?<=[a-zA-Z0-9\(\)])$' )]
1717 [string ] $BaseName ,
1818
19- [Parameter (ParameterSetName = ' ResourceGroup' , Mandatory = $true )]
20- [Parameter (ParameterSetName = ' ResourceGroup+Provisioner' , Mandatory = $true )]
19+ [Parameter (ParameterSetName = ' ResourceGroup' )]
20+ [Parameter (ParameterSetName = ' ResourceGroup+Provisioner' )]
2121 [string ] $ResourceGroupName ,
2222
2323 [Parameter (ParameterSetName = ' Default+Provisioner' , Mandatory = $true )]
@@ -48,6 +48,10 @@ param (
4848 [ValidateSet (' AzureCloud' , ' AzureUSGovernment' , ' AzureChinaCloud' , ' Dogfood' )]
4949 [string ] $Environment = ' AzureCloud' ,
5050
51+ [Parameter (ParameterSetName = ' ResourceGroup' )]
52+ [Parameter (ParameterSetName = ' ResourceGroup+Provisioner' )]
53+ [switch ] $CI ,
54+
5155 [Parameter ()]
5256 [switch ] $Force ,
5357
7377 $exitActions.Invoke ()
7478}
7579
80+ . $PSScriptRoot / SubConfig- Helpers.ps1
7681# Source helpers to purge resources.
7782. " $PSScriptRoot \..\scripts\Helpers\Resource-Helpers.ps1"
7883
@@ -126,18 +131,23 @@ if ($ProvisionerApplicationId) {
126131$context = Get-AzContext
127132
128133if (! $ResourceGroupName ) {
129- # Make sure $BaseName is set.
130- if (! $BaseName ) {
131- $UserName = if ($env: USER ) { $env: USER } else { " ${env: USERNAME} " }
132- # Remove spaces, etc. that may be in $UserName
133- $UserName = $UserName -replace ' \W'
134-
135- $BaseName = " $UserName$ServiceDirectory "
136- Log " BaseName was not set. Using default base name '$BaseName '"
137- }
134+ if ($CI ) {
135+ $envVarName = (BuildServiceDirectoryPrefix (GetServiceLeafDirectoryName $ServiceDirectory )) + " RESOURCE_GROUP"
136+ $ResourceGroupName = [Environment ]::GetEnvironmentVariable($envVarName )
137+ if (! $ResourceGroupName ) {
138+ Write-Error " Could not find resource group name environment variable '$envVarName '"
139+ exit 1
140+ }
141+ } else {
142+ if (! $BaseName ) {
143+ $UserName = GetUserName
144+ $BaseName = GetBaseName $UserName $ServiceDirectory
145+ Log " BaseName was not set. Using default base name '$BaseName '"
146+ }
138147
139- # Format the resource group name like in New-TestResources.ps1.
140- $ResourceGroupName = " rg-$BaseName "
148+ # Format the resource group name like in New-TestResources.ps1.
149+ $ResourceGroupName = " rg-$BaseName "
150+ }
141151}
142152
143153# If no subscription was specified, try to select the Azure SDK Developer Playground subscription.
@@ -282,6 +292,9 @@ specified - in which to discover pre removal script named 'remove-test-resources
282292Name of the cloud environment. The default is the Azure Public Cloud
283293('PublicCloud')
284294
295+ . PARAMETER CI
296+ Run script in CI mode. Infers various environment variable names based on CI convention.
297+
285298. PARAMETER Force
286299Force removal of resource group without asking for user confirmation
287300
0 commit comments