@@ -264,9 +264,10 @@ function SetDeploymentOutputs(
264
264
) {
265
265
$deploymentEnvironmentVariables = $environmentVariables.Clone ()
266
266
$deploymentOutputs = BuildDeploymentOutputs $serviceName $azContext $deployment $deploymentEnvironmentVariables
267
+ $isBicep = $templateFile.originalFilePath -and $templateFile.originalFilePath.EndsWith (" .bicep" )
267
268
268
- if ( $OutFile ) {
269
- if ($IsWindows -and $Language -eq ' dotnet' ) {
269
+ # Azure SDK for .NET on Windows uses DPAPI-encrypted, JSON-encoded environment variables.
270
+ if ($OutFile -and $IsWindows -and $Language -eq ' dotnet' ) {
270
271
$outputFile = " $ ( $templateFile.originalFilePath ) .env"
271
272
272
273
$environmentText = $deploymentOutputs | ConvertTo-Json ;
@@ -276,29 +277,29 @@ function SetDeploymentOutputs(
276
277
Set-Content $outputFile - Value $protectedBytes - AsByteStream - Force
277
278
278
279
Write-Host " Test environment settings`n $environmentText `n stored into encrypted $outputFile "
280
+ }
281
+ # Any Bicep template in a repo that has opted into .env files.
282
+ elseif ($OutFile -and $isBicep ) {
283
+ $bicepTemplateFile = $templateFile.originalFilePath
284
+
285
+ # Make sure the file would not write secrets to .env file.
286
+ if (! (LintBicepFile $bicepTemplateFile )) {
287
+ Write-Error " $bicepTemplateFile may write secrets. No file written."
279
288
}
280
- elseif ($templateFile.originalFilePath -and $templateFile.originalFilePath.EndsWith (" .bicep" )) {
281
- $bicepTemplateFile = $templateFile.originalFilePath
289
+ $outputFile = $bicepTemplateFile | Split-Path | Join-Path - ChildPath ' .env'
282
290
283
- # Make sure the file would not write secrets to .env file.
284
- if (! (LintBicepFile $bicepTemplateFile )) {
285
- Write-Error " $bicepTemplateFile may write secrets. No file written."
291
+ # Make sure the file would be ignored.
292
+ git check- ignore -- " $outputFile " > $null
293
+ if ($? ) {
294
+ $environmentText = foreach ($kv in $deploymentOutputs.GetEnumerator ()) {
295
+ " $ ( $kv.Key ) =`" $ ( $kv.Value ) `" "
286
296
}
287
- $outputFile = $bicepTemplateFile | Split-Path | Join-Path - ChildPath ' .env'
288
297
289
- # Make sure the file would be ignored.
290
- git check- ignore -- " $outputFile " > $null
291
- if ($? ) {
292
- $environmentText = foreach ($kv in $deploymentOutputs.GetEnumerator ()) {
293
- " $ ( $kv.Key ) =`" $ ( $kv.Value ) `" "
294
- }
295
-
296
- Set-Content $outputFile - Value $environmentText - Force
297
- Write-Host " Test environment settings`n $environmentText `n stored in $outputFile "
298
- }
299
- else {
300
- Write-Error " $outputFile is not ignored by .gitignore. No file written."
301
- }
298
+ Set-Content $outputFile - Value $environmentText - Force
299
+ Write-Host " Test environment settings`n $environmentText `n stored in $outputFile "
300
+ }
301
+ else {
302
+ Write-Error " $outputFile is not ignored by .gitignore. No file written."
302
303
}
303
304
}
304
305
else {
0 commit comments