-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
Jenkins 2.32.2
Hello
I don't understand how the powershell plugin handles the script result. I think $lastExitCode is always taken into account
As exemple
powershell(script: '''
$errorActionPreference="stop"
& cmd /C "echo toto"
write-error "fail"
''')
as a successful result
[Pipeline] {
[Pipeline] stage
[Pipeline]
{ (SCM) [Pipeline] powershell [Test] Running PowerShell script ���toto D:\Homeware\Jenkins-Slave-iron-1\workspace\Nightly\Test@tmp\durable-d84b797e\powershellMain.ps1 : fail At D:\workspace\Test@tmp\durable-d84b797e\powershellWrapper.ps1:1 char:1 + & "D:\workspace\Test@tmp\durable-d84b797e\ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellMain.ps1 [Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
but
powershell(script: '''
$errorActionPreference="stop"
write-error "fail"
''')
as a failure result
[Pipeline] {
[Pipeline] stage
[Pipeline]
{ (SCM) [Pipeline] powershell [Test] Running PowerShell script ���D:\workspace\Test@tmp\durable-81d739a3\powershellMain.ps1 : fail At D:\workspace\Nightly\Test@tmp\durable-81d739a3\powershellWrapper.ps1:1 char:1 + & "D:\Homeware\Jenkins-Slave-iron-1\workspace\Nightly\Test@tmp\durable-81d739a3\ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellMain.ps1 [Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
I need to add $global:lastExitCode = $null after each exe call to reset the lastExitCode variable