Skip to content

Conversation

@Mark-Corsillo-Bose
Copy link

This changes the "stopOnError" checkbox to a select, offering an option to not override the ErrorActionPreference for a script. This is to address situations where Powershell scripts include param() blocks, which causes a script to fail if there are any commands preceding them in a script.

https://issues.jenkins.io/browse/JENKINS-60423

Mark Corsillo added 2 commits February 11, 2022 16:00
This changes the "stopOnError" checkbox to a select, offering an option to *not* override the ErrorActionPreference for a script. This is to address situations where Powershell scripts include param() blocks, which causes a script to fail if there are any commands preceding them in a script.
@Mark-Corsillo-Bose
Copy link
Author

I think the test that failed is designed to fail to verify some functionality that was added in a recent version?

Assume.assumeTrue(isPowerShellAvailable());
FreeStyleProject project1 = r.createFreeStyleProject("project1");
project1.getBuildersList().add(new PowerShell("wrong command", true, true, null));
project1.getBuildersList().add(new PowerShell("wrong command", "noOverride", true, null));
Copy link
Member

Choose a reason for hiding this comment

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

should be stopOnError

where true was is now "stopOnError"

please add another test testBuildBadCommandisIgnored with "continueOnError"

Add a second test with a param() block

private Integer unstableReturn;

private final boolean stopOnError;
private String errorAction;
Copy link
Member

Choose a reason for hiding this comment

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

Upgrading a jenkins with existing jobs to this version fails:

ERROR: Build step failed with exception
java.lang.NullPointerException
	at hudson.plugins.powershell.PowerShell.getContents(PowerShell.java:129)
	at hudson.tasks.CommandInterpreter.createScriptFile(CommandInterpreter.java:202)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:120)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:92)
	at hudson.plugins.powershell.PowerShell.perform(PowerShell.java:48)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:21)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:808)
	at hudson.model.Build$BuildExecution.build(Build.java:199)
	at hudson.model.Build$BuildExecution.doRun(Build.java:164)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:516)
	at hudson.model.Run.execute(Run.java:1889)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:100)
	at hudson.model.Executor.run(Executor.java:433)
Build step 'PowerShell' marked build as failure
Finished: FAILURE

@Mark-Corsillo-Bose
Copy link
Author

Closing this PR in light of #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants