Skip to content

Commit fd5ba7b

Browse files
azure-sdkheaths
andauthored
Make sure we always log in as app or provisioner (Azure#17246)
This also adds previously-required parameters back into @PSBoundParameters to pass down to pre- and post-scripts. Co-authored-by: Heath Stewart <[email protected]>
1 parent fae262c commit fd5ba7b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ $UserName = if ($env:USER) { $env:USER } else { "${env:USERNAME}" }
141141
if (!$BaseName) {
142142
$BaseName = "$UserName$ServiceDirectory"
143143

144+
# Make sure pre- and post-scripts are passed formerly required arguments.
145+
$PSBoundParameters['BaseName'] = $BaseName
146+
144147
Log "BaseName was not set. Using default base name: '$BaseName'"
145148
}
146149

@@ -167,8 +170,7 @@ if (!$Location) {
167170
Write-Verbose "Location was not set. Using default location for environment: '$Location'"
168171
}
169172

170-
# If no test application ID is specified during an interactive session, create a new service principal.
171-
if (!$CI -and !$TestApplicationId) {
173+
if (!$CI) {
172174

173175
# Make sure the user is logged in to create a service principal.
174176
$context = Get-AzContext;
@@ -177,13 +179,20 @@ if (!$CI -and !$TestApplicationId) {
177179
$context = (Connect-AzAccount -Subscription $defaultSubscription).Context
178180
}
179181

180-
Log "TestApplicationId was not specified; creating a new service principal"
181-
$servicePrincipal = New-AzADServicePrincipal -Role Owner
182+
# If no test application ID is specified during an interactive session, create a new service principal.
183+
if (!$TestApplicationId) {
184+
Log "TestApplicationId was not specified; creating a new service principal"
185+
$servicePrincipal = New-AzADServicePrincipal -Role Owner
186+
187+
$TestApplicationId = $servicePrincipal.ApplicationId
188+
$TestApplicationSecret = (ConvertFrom-SecureString $servicePrincipal.Secret -AsPlainText);
182189

183-
$TestApplicationId = $servicePrincipal.ApplicationId
184-
$TestApplicationSecret = (ConvertFrom-SecureString $servicePrincipal.Secret -AsPlainText);
190+
# Make sure pre- and post-scripts are passed formerly required arguments.
191+
$PSBoundParameters['TestApplicationId'] = $TestApplicationId
192+
$PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret
185193

186-
Log "Created service principal '$TestApplicationId'"
194+
Log "Created service principal '$TestApplicationId'"
195+
}
187196

188197
if (!$ProvisionerApplicationId) {
189198
$ProvisionerApplicationId = $TestApplicationId

0 commit comments

Comments
 (0)