Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 4 additions & 9 deletions eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Invoke-LoggedCommand
[string] $ExecutePath,
[switch] $GroupOutput,
[int[]] $AllowedExitCodes = @(0),
[switch] $DoNotExitOnFailedExitCode,
[scriptblock] $OutputProcessor
)

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions eng/common/scripts/logging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function LogWarning {
Write-Host ("::warning::$args" -replace "`n", "%0D%0A")
}
else {
Write-Warning "$args"
Write-Host "$args" -ForegroundColor Yellow
}
}

Expand All @@ -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
}
}

Expand All @@ -71,7 +71,7 @@ function LogError {
Write-Host ("::error::$args" -replace "`n", "%0D%0A")
}
else {
Write-Error "$args"
Write-Host "$args" -ForegroundColor Red
}
}

Expand Down