Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
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: '''
                  $ErrorActionPreference="Stop"
                  cmd.exe /c "echo hello 1>&2"
                  
                '''

and the output:

[Pipeline] powershell
powershell.exe : cmd.exe : hello 
At C:Program Files (x86)JenkinsworkspacePowershellStderror@tmpdurable-3a4c71capowershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (cmd.exe : hello :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
At C:Program Files (x86)JenkinsworkspacePowershellStderror@tmpdurable-3a4c71capowershellScript.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 OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...