@@ -16,8 +16,8 @@ param (
16
16
[ValidatePattern (' ^[-a-zA-Z0-9\.\(\)_]{0,80}(?<=[a-zA-Z0-9\(\)])$' )]
17
17
[string ] $BaseName ,
18
18
19
- [Parameter (ParameterSetName = ' ResourceGroup' , Mandatory = $true )]
20
- [Parameter (ParameterSetName = ' ResourceGroup+Provisioner' , Mandatory = $true )]
19
+ [Parameter (ParameterSetName = ' ResourceGroup' )]
20
+ [Parameter (ParameterSetName = ' ResourceGroup+Provisioner' )]
21
21
[string ] $ResourceGroupName ,
22
22
23
23
[Parameter (ParameterSetName = ' Default+Provisioner' , Mandatory = $true )]
@@ -48,6 +48,10 @@ param (
48
48
[ValidateSet (' AzureCloud' , ' AzureUSGovernment' , ' AzureChinaCloud' , ' Dogfood' )]
49
49
[string ] $Environment = ' AzureCloud' ,
50
50
51
+ [Parameter (ParameterSetName = ' ResourceGroup' )]
52
+ [Parameter (ParameterSetName = ' ResourceGroup+Provisioner' )]
53
+ [switch ] $CI ,
54
+
51
55
[Parameter ()]
52
56
[switch ] $Force ,
53
57
73
77
$exitActions.Invoke ()
74
78
}
75
79
80
+ . $PSScriptRoot / SubConfig- Helpers.ps1
76
81
# Source helpers to purge resources.
77
82
. " $PSScriptRoot \..\scripts\Helpers\Resource-Helpers.ps1"
78
83
@@ -126,18 +131,23 @@ if ($ProvisionerApplicationId) {
126
131
$context = Get-AzContext
127
132
128
133
if (! $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
+ }
138
147
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
+ }
141
151
}
142
152
143
153
# 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
282
292
Name of the cloud environment. The default is the Azure Public Cloud
283
293
('PublicCloud')
284
294
295
+ . PARAMETER CI
296
+ Run script in CI mode. Infers various environment variable names based on CI convention.
297
+
285
298
. PARAMETER Force
286
299
Force removal of resource group without asking for user confirmation
287
300
0 commit comments