From 7a3f33249120ce33f103c2462febc4dbbcf06c4b Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 22 Oct 2025 09:45:26 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 12532 (#6800) * Change logging functions to use Write-Host Change logging helpers to always write to host and either set color or use devops/gh formatting. We do not want to use Write-Error or Write-Warning directly because they can stop the script or not depending on preferences which makes it difficult to ensure local runs of scripts work the same as in the pipelines. So, we should never depend on these logging commands to cause a script to stop execution. * Clean up error handling in CommandInvocation-Helpers Removed legacy error handling for command failures. * Fix error logging for command execution * Add option to skip exiting --------- Co-authored-by: Wes Haggard Co-authored-by: Wes Haggard --- .../scripts/Helpers/CommandInvocation-Helpers.ps1 | 13 ++++--------- eng/common/scripts/logging.ps1 | 6 +++--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 index 0c2431cc7..48b814987 100644 --- a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 +++ b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 @@ -23,6 +23,7 @@ function Invoke-LoggedCommand [string] $ExecutePath, [switch] $GroupOutput, [int[]] $AllowedExitCodes = @(0), + [switch] $DoNotExitOnFailedExitCode, [scriptblock] $OutputProcessor ) @@ -51,17 +52,11 @@ function Invoke-LoggedCommand LogGroupEnd } - if($LastExitCode -notin $AllowedExitCodes) + if($LASTEXITCODE -notin $AllowedExitCodes) { LogError "Command failed to execute ($duration): $Command`n" - - # This fix reproduces behavior that existed before - # https://github.com/Azure/azure-sdk-tools/pull/12235 - # Before that change, if a command failed Write-Error was always - # invoked in the failure case. Today, LogError only does Write-Error - # when running locally (not in a CI environment) - if ((Test-SupportsDevOpsLogging) -or (Test-SupportsGitHubLogging)) { - Write-Error "Command failed to execute ($duration): $Command`n" + if (!$DoNotExitOnFailedExitCode) { + exit $LASTEXITCODE } } else { diff --git a/eng/common/scripts/logging.ps1 b/eng/common/scripts/logging.ps1 index 4700a5716..c57bd0a51 100644 --- a/eng/common/scripts/logging.ps1 +++ b/eng/common/scripts/logging.ps1 @@ -38,7 +38,7 @@ function LogWarning { Write-Host ("::warning::$args" -replace "`n", "%0D%0A") } else { - Write-Warning "$args" + Write-Host "$args" -ForegroundColor Yellow } } @@ -59,7 +59,7 @@ function LogErrorForFile($file, $errorString) Write-Host ("::error file=$file,line=1,col=1::$errorString" -replace "`n", "%0D%0A") } else { - Write-Error "[Error in file $file]$errorString" + Write-Host "[Error in file $file]$errorString" -ForegroundColor Red } } @@ -71,7 +71,7 @@ function LogError { Write-Host ("::error::$args" -replace "`n", "%0D%0A") } else { - Write-Error "$args" + Write-Host "$args" -ForegroundColor Red } }