Skip to content

Commit 8ee6a50

Browse files
Sync eng/common directory with azure-sdk-tools for PR 12532 (#43570)
* 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 <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
1 parent d13e3af commit 8ee6a50

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function Invoke-LoggedCommand
2323
[string] $ExecutePath,
2424
[switch] $GroupOutput,
2525
[int[]] $AllowedExitCodes = @(0),
26+
[switch] $DoNotExitOnFailedExitCode,
2627
[scriptblock] $OutputProcessor
2728
)
2829

@@ -51,17 +52,11 @@ function Invoke-LoggedCommand
5152
LogGroupEnd
5253
}
5354

54-
if($LastExitCode -notin $AllowedExitCodes)
55+
if($LASTEXITCODE -notin $AllowedExitCodes)
5556
{
5657
LogError "Command failed to execute ($duration): $Command`n"
57-
58-
# This fix reproduces behavior that existed before
59-
# https://github.com/Azure/azure-sdk-tools/pull/12235
60-
# Before that change, if a command failed Write-Error was always
61-
# invoked in the failure case. Today, LogError only does Write-Error
62-
# when running locally (not in a CI environment)
63-
if ((Test-SupportsDevOpsLogging) -or (Test-SupportsGitHubLogging)) {
64-
Write-Error "Command failed to execute ($duration): $Command`n"
58+
if (!$DoNotExitOnFailedExitCode) {
59+
exit $LASTEXITCODE
6560
}
6661
}
6762
else {

eng/common/scripts/logging.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function LogWarning {
3838
Write-Host ("::warning::$args" -replace "`n", "%0D%0A")
3939
}
4040
else {
41-
Write-Warning "$args"
41+
Write-Host "$args" -ForegroundColor Yellow
4242
}
4343
}
4444

@@ -59,7 +59,7 @@ function LogErrorForFile($file, $errorString)
5959
Write-Host ("::error file=$file,line=1,col=1::$errorString" -replace "`n", "%0D%0A")
6060
}
6161
else {
62-
Write-Error "[Error in file $file]$errorString"
62+
Write-Host "[Error in file $file]$errorString" -ForegroundColor Red
6363
}
6464
}
6565

@@ -71,7 +71,7 @@ function LogError {
7171
Write-Host ("::error::$args" -replace "`n", "%0D%0A")
7272
}
7373
else {
74-
Write-Error "$args"
74+
Write-Host "$args" -ForegroundColor Red
7575
}
7676
}
7777

0 commit comments

Comments
 (0)