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

Add support to enable/disable PowerShell profile #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>durable-task</artifactId>
<version>1.36-rc473.404fedc2031a</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
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.
*/
public class PowershellScriptStep extends DurableTaskStep {

private final String script;
public boolean loadProfile;

@DataBoundConstructor public PowershellScriptStep(String script) {
if (script == null) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ THE SOFTWARE.
<f:entry field="script" title="PowerShell Script">
<f:textarea/>
</f:entry>
<f:entry field="loadProfile" title="Load Profile">
<f:checkbox />
</f:entry>

</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}