[JIRA] (JENKINS-36002) Add $ErrorActionPreference = "Stop" to the top of each script before executing

4 views
Skip to first unread message

ohads@microsoft.com (JIRA)

unread,
Jun 16, 2016, 5:00:01 AM6/16/16
to jenkinsc...@googlegroups.com
Ohad Schneider created an issue
 
Jenkins / Improvement JENKINS-36002
Add $ErrorActionPreference = "Stop" to the top of each script before executing
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: powershell-plugin
Created: 2016/Jun/16 8:59 AM
Environment: Jenkins 1.628
powershell-plugin 1.2
Priority: Minor Minor
Reporter: Ohad Schneider

Just as bash scripts are executed with set -e (as to terminate on any error), so should PowerShell scripts be executed with $ErrorActionPreference = "Stop" at the top (to the same effect).

Not only is it more consistent (e.g. with bash), it is also usually a more desirable behavior in CI scenarios (when you allow the script to continue you can miss important silent errors).

A user can always start his script with $ErrorActionPreference = "Continue" to override this, or it could be a checkbox, or the user could simply wrap potentially erronous statements in a try-catch block (probably the best solution).

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

nathandstovall@gmail.com (JIRA)

unread,
Aug 8, 2016, 1:26:02 PM8/8/16
to jenkinsc...@googlegroups.com
Nate Stovall commented on Improvement JENKINS-36002
 
Re: Add $ErrorActionPreference = "Stop" to the top of each script before executing

Instead of a fixed default, perhaps a dropdownbox of choices, with the default choice being the PowerShell default could be in put above the command text entry window.

Or, you can do what I do and put $ErrorActionPreference = "SilentlyContinue" as the first line of the script.

ohads@microsoft.com (JIRA)

unread,
Aug 8, 2016, 1:36:01 PM8/8/16
to jenkinsc...@googlegroups.com

Nate Stovall of course adding it manually is a possiblity, just as adding set -e to the top of each bash script would be. But the fact is, Jenkins effectively adds set -e to the top of each bash script without even asking you, so the most consistent thing to do would be do the PS equivalent which is $ErrorActionPreference = "SilentlyContinue". A dropdown (with stop as the default) would be even better, of course...

ohads@microsoft.com (JIRA)

unread,
Aug 8, 2016, 1:36:04 PM8/8/16
to jenkinsc...@googlegroups.com
Ohad Schneider edited a comment on Improvement JENKINS-36002
[~natestovall] of course adding it manually is a possiblity possibility , just as adding _set -e_ to the top of each bash script would be. But the fact is, Jenkins effectively adds _set -e_ to the top of each bash script without even asking you, so the most consistent thing to do would be do the PS equivalent which is _$ErrorActionPreference = "SilentlyContinue"_. A dropdown (with _stop_ as the default) would be even better, of course...

ohads@microsoft.com (JIRA)

unread,
Aug 8, 2016, 1:37:01 PM8/8/16
to jenkinsc...@googlegroups.com
Ohad Schneider edited a comment on Improvement JENKINS-36002
[~natestovall] of course adding it manually is a possibility, just as adding _set -e_ to the top of each bash script would be. But the fact is, Jenkins effectively adds _set -e_ to the top of each bash script without even asking you, so the most consistent thing to do would be do to use the PS equivalent which is _$ErrorActionPreference = "SilentlyContinue"_. A dropdown (with _stop_ as the default) would be even better, of course...

rausalinas@gmail.com (JIRA)

unread,
Jun 11, 2019, 3:40:02 AM6/11/19
to jenkinsc...@googlegroups.com

This is a great idea, in most cases, you don't want scripts to go on when they encounter failures. I'd rather have false positive abortions than false negatives. 

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

privat@michaelbrunner.de (JIRA)

unread,
Sep 30, 2019, 12:41:04 PM9/30/19
to jenkinsc...@googlegroups.com

Just had the same issue. Script expected some argument, which I didn't pass in. Jenkins still shows green.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages