diff --git a/pom.xml b/pom.xml index e45fb76b..7ca50483 100644 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,7 @@ org.jenkins-ci.plugins durable-task + 1.36-rc473.404fedc2031a org.jenkins-ci.plugins.workflow diff --git a/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep.java b/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep.java index 9fc0eced..102f44cc 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep.java @@ -28,6 +28,7 @@ import org.jenkinsci.plugins.durabletask.DurableTask; import org.jenkinsci.plugins.durabletask.PowershellScript; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; /** * Asynchronous batch script execution. @@ -35,6 +36,7 @@ public class PowershellScriptStep extends DurableTaskStep { private final String script; + public boolean loadProfile; @DataBoundConstructor public PowershellScriptStep(String script) { if (script == null) { @@ -47,8 +49,19 @@ public String getScript() { return script; } + public boolean isLoadProfile() { + return loadProfile; + } + + @DataBoundSetter + public void setLoadProfile(boolean loadProfile) { + this.loadProfile = loadProfile; + } + @Override protected DurableTask task() { - return new PowershellScript(script); + PowershellScript ps = new PowershellScript(script); + ps.setLoadProfile(loadProfile); + return ps; } @Extension public static final class DescriptorImpl extends DurableTaskStepDescriptor { diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep/config-details.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep/config-details.jelly index 9b64dae3..2b1e5618 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep/config-details.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/PowershellScriptStep/config-details.jelly @@ -27,4 +27,8 @@ THE SOFTWARE. + + + + diff --git a/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowerShellStepTest.java b/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowerShellStepTest.java index 28165218..a113c6b6 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowerShellStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/PowerShellStepTest.java @@ -73,5 +73,21 @@ public class PowerShellStepTest { Assume.assumeTrue("Correct UTF-8 output should be produced",log.contains("Hëllö Wórld")); } + @Test public void testNoProfile() throws Exception { + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "baz"); + p.setDefinition(new CpsFlowDefinition("node { powershell(script: 'if ((Get-CimInstance Win32_Process -Filter \"ProcessId = $PID\").CommandLine.split(\" \").Contains(\"-NoProfile\")) { exit 0; } else { exit 1; } ')}", true)); + WorkflowRun b = p.scheduleBuild2(0).get(); + Result r = b.getResult(); + Assume.assumeTrue("The plugin defaults to run Powershell with the -NoProfile option", r == Result.SUCCESS); + } + + @Test public void testWithProfile() throws Exception { + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "bazooka"); + p.setDefinition(new CpsFlowDefinition("node { powershell(loadProfile: true, script: 'if ((Get-CimInstance Win32_Process -Filter \"ProcessId = $PID\").CommandLine.split(\" \").Contains(\"-NoProfile\")) { exit 0; } else { exit 1; } ')}", true)); + WorkflowRun b = p.scheduleBuild2(0).get(); + Result r = b.getResult(); + Assume.assumeTrue("The plugin defaults to run Powershell with the -NoProfile option", r == Result.FAILURE); + } + }