Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

Write to standard error in powershell fails jenkins job?

The documentation page of Microsoft Powershell support for Pipeline (Which is part of the Processes and Nodes plugin, not the powershell plugin!!) says that the following:

node {
    def stdout = powershell(returnStdout: true, script: '''
      Write-Error 'Something terrible has happened!'

Will fail the job, since:

The failure in this example is due to the PowerShell error stream being non-empty, which therefore caused the step to result in a non-zero exit status.

Incidentally, this is not accurate since in order for the job to fail you have to add

$ErrorActionPreference = "Stop"

However, I tried the following:

 powershell script: '''
                  cmd.exe /c "echo hello 1>&2"

and the output:

[Pipeline] powershell
powershell.exe : cmd.exe : hello 
At C:Program Files (x86)[email protected]Wrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (cmd.exe : hello :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
At C:Program Files (x86)[email protected]Script.ps1:2 char:19
+                   cmd.exe /c "echo hello 1>&2" 2>&1
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (hello :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

So although there is a write to the error stream, the job doesn't fail, which is not exactly what's noted in the docs.

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share