Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Support stopOnError for PS
  • Loading branch information
mbaitelman-bitburst-ops committed Jan 20, 2022
commit f902cf2adb33146893f09ec61db6a4e8422dee4f
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ public class PowershellScriptStep extends DurableTaskStep {

private final String script;

@DataBoundConstructor public PowershellScriptStep(String script) {
@DataBoundConstructor public PowershellScriptStep(String script, boolean stopOnError) {
if (script == null) {
throw new IllegalArgumentException();
}
if(stopOnError){
script = "$ErrorActionPreference=\"Stop\"" + script;
}
this.script = script;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public class PowerShellStepTest {
p.setDefinition(new CpsFlowDefinition("node {powershell 'throw \"bogus error\"'}", true));
j.assertLogContains("bogus error", j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)));
}

// Test that a powershell step that fails indeed causes the underlying build to fail with stopOnFailure: true
@Test public void testStopOnFailure() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "stopfailure");
p.setDefinition(new CpsFlowDefinition("node {powershell( script: 'throw \"bogus error\"', stopOnFailure: true)}", true));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make the job do more after the error step (like print a line) and verify that the subsequent actions do not appear

j.assertLogContains("bogus error", j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)));
}

@Test public void testUnicode() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "foobar");
Expand Down