In a Jenkins script, I do :
def status = powershell(
script: """
# Display current directory
Write-Host "Current directory: \$(Get-Location)"
# Display Git version
git --version
# Display HEAD's SHA
git rev-parse HEAD
# Test git diff
Write-Host "git diff --quiet ${some_SHA1} HEAD --"
git diff --quiet ${some_SHA1} HEAD --
\$code = \$LASTEXITCODE
Write-Host "Git exited with code \$code"
exit \$LASTEXITCODE
""",
returnStatus: true)
print "status = ${status}"
${some_SHA1}
is a random SHA1. There is no associated commit.
In this case, the Git command returns 128 as exit code, and some error message on the prompt.
On the system where Jenkins is hosted and executed, I tested the command in the current directory displayed by the script, and it does what is expected.
But the script, after the git diff
command, display:
Git exited with code 0
The value should be 128.
And of course, outside the Powershell script, status = 0.
I tested also with cmd()
command, and I got the same result.
I don't understand this behavior. Would anyone have an explanation ?
EDIT 1: Add independent PowerShell script:
param($some_SHA1)
# Display current directory
Write-Host "Current directory: $(Get-Location)"
# Display Git version
git --version
# Display HEAD's SHA
git rev-parse HEAD
# Test git diff
Write-Host "git diff --quiet ${some_SHA1} HEAD --"
git diff --quiet ${some_SHA1} HEAD --
$code = $LASTEXITCODE
Write-Host "Git exited with code \$code"
exit $LASTEXITCODE
Works as expected when run from Powershell prompt:
- the trace instruction in the Powershell code outputs 128
- the code return (
$LASTEXITCODE
) called on the prompt outputs 128
Works as expected when run from cmd prompt:
- the trace instruction in the Powershell code outputs 128
- the code return (
$?
) called on the prompt outputsFalse
EDIT 2: I am wondering if Jenkins restrict the reading of the value on 7 bits...