Skip to content

Commit

Permalink
Fail fast on variable conflicts with subscription config (Azure#6853)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbp authored Aug 25, 2023
1 parent 3ee7642 commit a87d4c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eng/common/TestResources/SubConfig-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@ function SetSubscriptionConfiguration([object]$subscriptionConfiguration)
# Mark values as secret so we don't print json blobs containing secrets in the logs.
# Prepend underscore to the variable name, so we can still access the variable names via environment
# variables if they get set subsequently.
if ([Environment]::GetEnvironmentVariable($nestedPair.Name)) {
throw "Environment variable '$($nestedPair.Name)' is already set. Check the tests.yml/ci.yml EnvVars parameter does not conflict with the subscription config json"
}
if (ShouldMarkValueAsSecret "AZURE_" $nestedPair.Name $nestedPair.Value) {
Write-Host "##vso[task.setvariable variable=_$($nestedPair.Name);issecret=true;]$($nestedPair.Value)"
}
}
} else {
if ([Environment]::GetEnvironmentVariable($pair.Name)) {
throw "Environment variable '$($pair.Name)' is already set. Check the tests.yml/ci.yml EnvVars parameter does not conflict with the subscription config json"
}
if (ShouldMarkValueAsSecret "AZURE_" $pair.Name $pair.Value) {
Write-Host "##vso[task.setvariable variable=_$($pair.Name);issecret=true;]$($pair.Value)"
}
Expand Down
8 changes: 8 additions & 0 deletions eng/common/TestResources/build-test-resource-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ parameters:
- name: SubscriptionConfigurations
type: object
default: null
# EnvVars is used to help diagnose variable conflict issues early
- name: EnvVars
type: object
default: null

steps:
- ${{ if parameters.SubscriptionConfiguration }}:
Expand All @@ -16,6 +20,8 @@ steps:
. ./eng/common/TestResources/SubConfig-Helpers.ps1
SetSubscriptionConfiguration $config
displayName: Initialize SubscriptionConfiguration variable
${{ if parameters.EnvVars }}:
env: ${{ parameters.EnvVars }}
- ${{ if parameters.SubscriptionConfigurations }}:
- pwsh: |
Expand All @@ -36,3 +42,5 @@ steps:
UpdateSubscriptionConfiguration $configBase $config
displayName: Merge Test Resource Configurations
${{ if parameters.EnvVars }}:
env: ${{ parameters.EnvVars }}

0 comments on commit a87d4c1

Please sign in to comment.