From e2f10c29b22d7855624444bcaf284ab35fdfeae1 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Thu, 16 Oct 2025 14:11:05 -0700 Subject: [PATCH 1/4] 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. --- eng/common/scripts/logging.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/logging.ps1 b/eng/common/scripts/logging.ps1 index 4700a5716453..c57bd0a51972 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 } } From daf7a738385f597e6082ef5d146e5a515c3cede2 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Thu, 16 Oct 2025 14:12:36 -0700 Subject: [PATCH 2/4] Clean up error handling in CommandInvocation-Helpers Removed legacy error handling for command failures. --- eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 | 9 --------- 1 file changed, 9 deletions(-) diff --git a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 index 0c2431cc7e74..9475164a59ed 100644 --- a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 +++ b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 @@ -54,15 +54,6 @@ function Invoke-LoggedCommand 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" - } } else { Write-Host "Command succeeded ($duration)`n" From 35374dd0a41641b56f7f4a065e2f1258b1b1fe98 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Fri, 17 Oct 2025 09:01:59 -0700 Subject: [PATCH 3/4] Fix error logging for command execution --- eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 index 9475164a59ed..680fcbef3757 100644 --- a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 +++ b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 @@ -54,6 +54,7 @@ function Invoke-LoggedCommand if($LastExitCode -notin $AllowedExitCodes) { LogError "Command failed to execute ($duration): $Command`n" + exit $LastExitCode } else { Write-Host "Command succeeded ($duration)`n" From d6e66a0eda5a5edc6bd4516615a8fab7fa0c60c4 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Tue, 21 Oct 2025 15:28:05 -0700 Subject: [PATCH 4/4] Add option to skip exiting --- eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 b/eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1 index 680fcbef3757..48b81498728c 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,10 +52,12 @@ function Invoke-LoggedCommand LogGroupEnd } - if($LastExitCode -notin $AllowedExitCodes) + if($LASTEXITCODE -notin $AllowedExitCodes) { LogError "Command failed to execute ($duration): $Command`n" - exit $LastExitCode + if (!$DoNotExitOnFailedExitCode) { + exit $LASTEXITCODE + } } else { Write-Host "Command succeeded ($duration)`n"