Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions eng/common/TestResources/TestResources-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ function SetDeploymentOutputs(
) {
$deploymentEnvironmentVariables = $environmentVariables.Clone()
$deploymentOutputs = BuildDeploymentOutputs $serviceName $azContext $deployment $deploymentEnvironmentVariables
$isBicep = $templateFile.originalFilePath -and $templateFile.originalFilePath.EndsWith(".bicep")

if ($OutFile) {
if ($IsWindows -and $Language -eq 'dotnet') {
# Azure SDK for .NET on Windows uses DPAPI-encrypted, JSON-encoded environment variables.
if ($OutFile -and $IsWindows -and $Language -eq 'dotnet') {
$outputFile = "$($templateFile.originalFilePath).env"

$environmentText = $deploymentOutputs | ConvertTo-Json;
Expand All @@ -276,29 +277,29 @@ function SetDeploymentOutputs(
Set-Content $outputFile -Value $protectedBytes -AsByteStream -Force

Write-Host "Test environment settings`n$environmentText`nstored into encrypted $outputFile"
}
# Any Bicep template in a repo that has opted into .env files.
elseif ($OutFile -and $isBicep) {
$bicepTemplateFile = $templateFile.originalFilePath

# Make sure the file would not write secrets to .env file.
if (!(LintBicepFile $bicepTemplateFile)) {
Write-Error "$bicepTemplateFile may write secrets. No file written."
}
elseif ($templateFile.originalFilePath -and $templateFile.originalFilePath.EndsWith(".bicep")) {
$bicepTemplateFile = $templateFile.originalFilePath
$outputFile = $bicepTemplateFile | Split-Path | Join-Path -ChildPath '.env'

# Make sure the file would not write secrets to .env file.
if (!(LintBicepFile $bicepTemplateFile)) {
Write-Error "$bicepTemplateFile may write secrets. No file written."
# Make sure the file would be ignored.
git check-ignore -- "$outputFile" > $null
if ($?) {
$environmentText = foreach ($kv in $deploymentOutputs.GetEnumerator()) {
"$($kv.Key)=`"$($kv.Value)`""
}
$outputFile = $bicepTemplateFile | Split-Path | Join-Path -ChildPath '.env'

# Make sure the file would be ignored.
git check-ignore -- "$outputFile" > $null
if ($?) {
$environmentText = foreach ($kv in $deploymentOutputs.GetEnumerator()) {
"$($kv.Key)=`"$($kv.Value)`""
}

Set-Content $outputFile -Value $environmentText -Force
Write-Host "Test environment settings`n$environmentText`nstored in $outputFile"
}
else {
Write-Error "$outputFile is not ignored by .gitignore. No file written."
}
Set-Content $outputFile -Value $environmentText -Force
Write-Host "Test environment settings`n$environmentText`nstored in $outputFile"
}
else {
Write-Error "$outputFile is not ignored by .gitignore. No file written."
}
}
else {
Expand Down