Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes force insertion of '$ErrorActionPreference = "Continue"' if "Stop On Errors" is unchecked #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/main/java/hudson/plugins/powershell/PowerShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
public boolean isStopOnError() {
return stopOnError;
}

public boolean isUseProfile() {
return useProfile;
}
Expand Down Expand Up @@ -132,10 +132,8 @@ protected String getContents() {
StringBuilder sb = new StringBuilder();
if (stopOnError) {
sb.append("$ErrorActionPreference=\"Stop\"");
} else {
sb.append("$ErrorActionPreference=\"Continue\"");
sb.append(System.lineSeparator());
}
sb.append(System.lineSeparator());
sb.append(command);
sb.append(System.lineSeparator());
sb.append("exit $LastExitCode");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div>
<p>Stops script when some step fails. Similar to Shell set -e. Translates to $ErrorActionPreference Stop or Continue. See <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6#erroractionpreference">documentation</a>.</p>
<p>Stops script when some step fails. Similar to Shell set -e. Translates to inserting the line '$ErrorActionPreference = "Stop"' into the beginning of your command block. <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.3#erroractionpreference">See documentation on ErrorActionPreference</a>.
<br />However, this can break scripts that have advanced parameter blocks, specifically those utilizing '[CmdletBinding()]' in the beginning as this must be the first executable line in a scriptblock, resulting in an 'UnexpectedAttribute' error.
</p>
</div>