Skip to content

Commit 71de438

Browse files
azure-sdkbenbp
andauthored
Fail fast on variable conflicts with subscription config (Azure#36534)
Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
1 parent 76ffdbb commit 71de438

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

eng/common/TestResources/SubConfig-Helpers.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@ function SetSubscriptionConfiguration([object]$subscriptionConfiguration)
109109
# Mark values as secret so we don't print json blobs containing secrets in the logs.
110110
# Prepend underscore to the variable name, so we can still access the variable names via environment
111111
# variables if they get set subsequently.
112+
if ([Environment]::GetEnvironmentVariable($nestedPair.Name)) {
113+
throw "Environment variable '$($nestedPair.Name)' is already set. Check the tests.yml/ci.yml EnvVars parameter does not conflict with the subscription config json"
114+
}
112115
if (ShouldMarkValueAsSecret "AZURE_" $nestedPair.Name $nestedPair.Value) {
113116
Write-Host "##vso[task.setvariable variable=_$($nestedPair.Name);issecret=true;]$($nestedPair.Value)"
114117
}
115118
}
116119
} else {
120+
if ([Environment]::GetEnvironmentVariable($pair.Name)) {
121+
throw "Environment variable '$($pair.Name)' is already set. Check the tests.yml/ci.yml EnvVars parameter does not conflict with the subscription config json"
122+
}
117123
if (ShouldMarkValueAsSecret "AZURE_" $pair.Name $pair.Value) {
118124
Write-Host "##vso[task.setvariable variable=_$($pair.Name);issecret=true;]$($pair.Value)"
119125
}

eng/common/TestResources/build-test-resource-config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ parameters:
55
- name: SubscriptionConfigurations
66
type: object
77
default: null
8+
# EnvVars is used to help diagnose variable conflict issues early
9+
- name: EnvVars
10+
type: object
11+
default: null
812

913
steps:
1014
- ${{ if parameters.SubscriptionConfiguration }}:
@@ -16,6 +20,8 @@ steps:
1620
. ./eng/common/TestResources/SubConfig-Helpers.ps1
1721
SetSubscriptionConfiguration $config
1822
displayName: Initialize SubscriptionConfiguration variable
23+
${{ if parameters.EnvVars }}:
24+
env: ${{ parameters.EnvVars }}
1925
2026
- ${{ if parameters.SubscriptionConfigurations }}:
2127
- pwsh: |
@@ -36,3 +42,5 @@ steps:
3642
UpdateSubscriptionConfiguration $configBase $config
3743
3844
displayName: Merge Test Resource Configurations
45+
${{ if parameters.EnvVars }}:
46+
env: ${{ parameters.EnvVars }}

0 commit comments

Comments
 (0)