From c525c23c95c1584eb519fa9c134485368c759a84 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Mon, 19 Apr 2021 15:57:53 -0400 Subject: [PATCH] Use underscore-prefixed variable name when setting sub config values as secrets --- .../TestResources/build-test-resource-config.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/eng/common/TestResources/build-test-resource-config.yml b/eng/common/TestResources/build-test-resource-config.yml index 98cdd96f5ad6..9aeaca918df6 100644 --- a/eng/common/TestResources/build-test-resource-config.yml +++ b/eng/common/TestResources/build-test-resource-config.yml @@ -16,10 +16,13 @@ steps: foreach($pair in $config.GetEnumerator()) { if ($pair.Value -is [Hashtable]) { foreach($nestedPair in $pair.Value.GetEnumerator()) { - Write-Host "##vso[task.setvariable variable=$($nestedPair.Name);issecret=true;]$($nestedPair.Value)" + # 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. + Write-Host "##vso[task.setvariable variable=_$($nestedPair.Name);issecret=true;]$($nestedPair.Value)" } } else { - Write-Host "##vso[task.setvariable variable=$($pair.Name);issecret=true;]$($pair.Value)" + Write-Host "##vso[task.setvariable variable=_$($pair.Name);issecret=true;]$($pair.Value)" } } @@ -49,11 +52,14 @@ steps: $config[$pair.Name] = @{} } foreach($nestedPair in $pair.Value.GetEnumerator()) { - Write-Host "##vso[task.setvariable variable=$($nestedPair.Name);issecret=true;]$($nestedPair.Value)" + # 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. + Write-Host "##vso[task.setvariable variable=_$($nestedPair.Name);issecret=true;]$($nestedPair.Value)" $config[$pair.Name][$nestedPair.Name] = $nestedPair.Value } } else { - Write-Host "##vso[task.setvariable variable=$($pair.Name);issecret=true;]$($pair.Value)" + Write-Host "##vso[task.setvariable variable=_$($pair.Name);issecret=true;]$($pair.Value)" $config[$pair.Name] = $pair.Value } }