From 80b6fc60222bee5e25324562f8273039df37d16f Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:22:14 -0700 Subject: [PATCH] Fail fast on variable conflicts with subscription config (#4915) Co-authored-by: Ben Broderick Phillips --- eng/common/TestResources/SubConfig-Helpers.ps1 | 6 ++++++ eng/common/TestResources/build-test-resource-config.yml | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/eng/common/TestResources/SubConfig-Helpers.ps1 b/eng/common/TestResources/SubConfig-Helpers.ps1 index 4ef744828..9b69c516b 100644 --- a/eng/common/TestResources/SubConfig-Helpers.ps1 +++ b/eng/common/TestResources/SubConfig-Helpers.ps1 @@ -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)" } diff --git a/eng/common/TestResources/build-test-resource-config.yml b/eng/common/TestResources/build-test-resource-config.yml index 2335f94f4..2f158c475 100644 --- a/eng/common/TestResources/build-test-resource-config.yml +++ b/eng/common/TestResources/build-test-resource-config.yml @@ -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 }}: @@ -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: | @@ -36,3 +42,5 @@ steps: UpdateSubscriptionConfiguration $configBase $config displayName: Merge Test Resource Configurations + ${{ if parameters.EnvVars }}: + env: ${{ parameters.EnvVars }}