Skip to content

Commit 87c077d

Browse files
danieljurekazure-sdk
authored andcommitted
Template conditions use AzurePowerShell only when a service connection is needed
1 parent 155d56f commit 87c077d

File tree

2 files changed

+68
-22
lines changed

2 files changed

+68
-22
lines changed

eng/common/TestResources/deploy-test-resources.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
parameters:
32
ServiceDirectory: not-set
43
ArmTemplateParameters: '@{}'
@@ -42,16 +41,40 @@ steps:
4241

4342
- template: /eng/common/TestResources/setup-environments.yml
4443

45-
- task: AzurePowerShell@5
46-
displayName: Deploy test resources
47-
env:
48-
TEMP: $(Agent.TempDirectory)
49-
inputs:
50-
azureSubscription: ${{ parameters.ServiceConnection }}
51-
azurePowerShellVersion: LatestVersion
52-
pwsh: true
53-
ScriptType: InlineScript
54-
Inline: |
44+
- ${{ if eq('true', parameters.UseFederatedAuth) }}:
45+
- task: AzurePowerShell@5
46+
displayName: Deploy test resources
47+
env:
48+
TEMP: $(Agent.TempDirectory)
49+
inputs:
50+
azureSubscription: ${{ parameters.ServiceConnection }}
51+
azurePowerShellVersion: LatestVersion
52+
pwsh: true
53+
ScriptType: InlineScript
54+
Inline: |
55+
eng/common/scripts/Import-AzModules.ps1
56+
57+
$subscriptionConfiguration = @'
58+
${{ parameters.SubscriptionConfiguration }}
59+
'@ | ConvertFrom-Json -AsHashtable;
60+
61+
# The subscriptionConfiguration may have ArmTemplateParameters defined, so
62+
# pass those in via the ArmTemplateParameters flag, and handle any
63+
# additional parameters from the pipelines via AdditionalParameters
64+
eng/common/TestResources/New-TestResources.ps1 `
65+
-ResourceType '${{ parameters.ResourceType }}' `
66+
-ServiceDirectory '${{ parameters.ServiceDirectory }}' `
67+
-Location '${{ parameters.Location }}' `
68+
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
69+
@subscriptionConfiguration `
70+
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
71+
-CI `
72+
-UseFederatedAuth `
73+
-Force `
74+
-Verbose | Out-Null
75+
76+
- ${{ else }}:
77+
- pwsh: |
5578
eng/common/scripts/Import-AzModules.ps1
5679
5780
$subscriptionConfiguration = @'
@@ -69,6 +92,8 @@ steps:
6992
@subscriptionConfiguration `
7093
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
7194
-CI `
72-
-FederatedAuth:$${{ parameters.UseFederatedAuth }} `
7395
-Force `
7496
-Verbose | Out-Null
97+
displayName: Deploy test resources
98+
env:
99+
TEMP: $(Agent.TempDirectory)

eng/common/TestResources/remove-test-resources.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,34 @@ parameters:
2323
# not error when parameters are provided which the script doesn't use.
2424

2525
steps:
26-
- task: AzurePowerShell@5
27-
displayName: Remove test resources
28-
condition: and(eq(variables['CI_HAS_DEPLOYED_RESOURCES'], 'true'), ne(variables['Skip.RemoveTestResources'], 'true'))
29-
inputs:
30-
azureSubscription: ${{ parameters.ServiceConnection }}
31-
azurePowerShellVersion: LatestVersion
32-
pwsh: true
33-
ScriptType: InlineScript
34-
Inline: |
26+
- ${{ if eq('true', parameters.UseFederatedAuth) }}:
27+
- task: AzurePowerShell@5
28+
displayName: Remove test resources
29+
condition: and(eq(variables['CI_HAS_DEPLOYED_RESOURCES'], 'true'), ne(variables['Skip.RemoveTestResources'], 'true'))
30+
continueOnError: true
31+
inputs:
32+
azureSubscription: ${{ parameters.ServiceConnection }}
33+
azurePowerShellVersion: LatestVersion
34+
pwsh: true
35+
ScriptType: InlineScript
36+
Inline: |
37+
eng/common/scripts/Import-AzModules.ps1
38+
39+
$subscriptionConfiguration = @"
40+
${{ parameters.SubscriptionConfiguration }}
41+
"@ | ConvertFrom-Json -AsHashtable;
42+
43+
eng/common/TestResources/Remove-TestResources.ps1 `
44+
@subscriptionConfiguration `
45+
-ResourceType '${{ parameters.ResourceType }}' `
46+
-ServiceDirectory "${{ parameters.ServiceDirectory }}" `
47+
-CI `
48+
-Force `
49+
-UseFederatedAuth `
50+
-Verbose
51+
52+
- ${{ else }}:
53+
- pwsh: |
3554
eng/common/scripts/Import-AzModules.ps1
3655
3756
$subscriptionConfiguration = @"
@@ -44,5 +63,7 @@ steps:
4463
-ServiceDirectory "${{ parameters.ServiceDirectory }}" `
4564
-CI `
4665
-Force `
47-
-FederatedAuth:$${{ parameters.UseFederatedAuth }} `
4866
-Verbose
67+
displayName: Remove test resources
68+
condition: and(eq(variables['CI_HAS_DEPLOYED_RESOURCES'], 'true'), ne(variables['Skip.RemoveTestResources'], 'true'))
69+
continueOnError: true

0 commit comments

Comments
 (0)