From 9ceee65a6dbcad9eebc32c05048a6deb226c5eae Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Thu, 23 Apr 2020 15:11:25 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools repository (#83) --- .../TestResources/New-TestResources.ps1 | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 133137ea7..51bc247ec 100644 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -172,19 +172,20 @@ if ($TestApplicationId -and !$TestApplicationOid) { } } + +# If the ServiceDirectory is an absolute path use the last directory name +# (e.g. D:\foo\bar\ -> bar) +$serviceName = if (Split-Path -IsAbsolute $ServiceDirectory) { + Split-Path -Leaf $ServiceDirectory +} else { + $ServiceDirectory +} + # Format the resource group name based on resource group naming recommendations and limitations. $resourceGroupName = if ($CI) { $BaseName = 't' + (New-Guid).ToString('n').Substring(0, 16) Write-Verbose "Generated base name '$BaseName' for CI build" - # If the ServiceDirectory is an absolute path use the last directory name - # (e.g. D:\foo\bar\ -> bar) - $serviceName = if (Split-Path -IsAbsolute $ServiceDirectory) { - Split-Path -Leaf $ServiceDirectory - } else { - $ServiceDirectory - } - "rg-{0}-$BaseName" -f ($serviceName -replace '[\\\/:]', '-').Substring(0, [Math]::Min($serviceName.Length, 90 - $BaseName.Length - 4)).Trim('-') } else { "rg-$BaseName" @@ -286,7 +287,21 @@ foreach ($templateFile in $templateFiles) { Log "Persist the following environment variables based on your detected shell ($shell):`n" } - $deploymentOutputs = @{} + $serviceDirectoryPrefix = $serviceName.ToUpperInvariant() + "_" + + $context = Get-AzContext; + + # Add default values + $deploymentOutputs = @{ + "$($serviceDirectoryPrefix)CLIENT_ID" = $TestApplicationId; + "$($serviceDirectoryPrefix)CLIENT_SECRET" = $TestApplicationSecret; + "$($serviceDirectoryPrefix)TENANT_ID" = $context.Tenant.Id; + "$($serviceDirectoryPrefix)SUBSCRIPTION_ID" = $context.Subscription.Id; + "$($serviceDirectoryPrefix)RESOURCE_GROUP" = $resourceGroup.ResourceGroupName; + "$($serviceDirectoryPrefix)LOCATION" = $resourceGroup.Location; + "$($serviceDirectoryPrefix)ENVIRONMENT" = $context.Environment; + } + foreach ($key in $deployment.Outputs.Keys) { $variable = $deployment.Outputs[$key] @@ -295,16 +310,21 @@ foreach ($templateFile in $templateFiles) { if ($variable.Type -eq 'String' -or $variable.Type -eq 'SecureString') { $deploymentOutputs[$key] = $variable.Value + } + } - if ($CI) { - # Treat all ARM template output variables as secrets since "SecureString" variables do not set values. - # In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below. - Write-Host "Setting variable '$key': ***" - Write-Host "##vso[task.setvariable variable=_$key;issecret=true;]$($variable.Value)" - Write-Host "##vso[task.setvariable variable=$key;]$($variable.Value)" - } else { - Write-Host ($shellExportFormat -f $key, $variable.Value) - } + foreach ($key in $deploymentOutputs.Keys) + { + $value = $deploymentOutputs[$key] + + if ($CI) { + # Treat all ARM template output variables as secrets since "SecureString" variables do not set values. + # In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below. + Write-Host "Setting variable '$key': ***" + Write-Host "##vso[task.setvariable variable=_$key;issecret=true;]$($value)" + Write-Host "##vso[task.setvariable variable=$key;]$($value)" + } else { + Write-Host ($shellExportFormat -f $key, $value) } }