Skip to content

Commit

Permalink
Rename sshExecuteCommand and sshExecuteScript
Browse files Browse the repository at this point in the history
- To sshCommand and sshScript
- And add blue ocean screenshot
  • Loading branch information
nrayapati committed Jun 22, 2018
1 parent 5ab18d1 commit 72cd0a3
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 44 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
== 1.0.0 (Unreleased)
* Initial release.
* Supported Steps.
** sshExecuteCommand
** sshExecuteScript
** sshCommand
** sshScript
** sshGet
** sshPut
** sshRemove
20 changes: 12 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Most of the steps in this plugin require a common step variable called `remote`,

The following pipeline steps are available with the initial version of this plugin.

=== sshExecuteCommand
=== sshCommand

This step executes given command on remote node and responds with output.

Expand Down Expand Up @@ -187,12 +187,12 @@ This step executes given command on remote node and responds with output.
remote.password = 'password'
remote.allowAnyHosts = true
stage('Remote SSH') {
sshExecuteCommand remote: remote, command: "ls -lrt"
sshExecuteCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
sshCommand remote: remote, command: "ls -lrt"
sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
}
```

=== sshExecuteScript
=== sshScript

This step executes given script(file) on remote node and responds with output.

Expand Down Expand Up @@ -232,7 +232,7 @@ This step executes given script(file) on remote node and responds with output.
remote.allowAnyHosts = true
stage('Remote SSH') {
writeFile file: 'abc.sh', text: 'ls -lrt'
sshExecuteScript remote: remote, script: "abc.sh"
sshScript remote: remote, script: "abc.sh"
}
```

Expand Down Expand Up @@ -390,17 +390,21 @@ node {
remote.identityFile = identity
stage("SSH Steps Rocks!") {
writeFile file: 'abc.sh', text: 'ls'
sshExecuteCommand remote: remote, command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done'
sshCommand remote: remote, command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done'
sshPut remote: remote, from: 'abc.sh', into: '.'
sshGet remote: remote, from: 'abc.sh', into: 'bac.sh', override: true
sshExecuteScript remote: remote, script: 'abc.sh'
sshScript remote: remote, script: 'abc.sh'
sshRemove remote: remote, path: 'abc.sh'
}
}
}
```

image::docs/static/ExampleWithCredentials.png[Example,300]
==== Classic View:
image::docs/static/ExampleWithCredentials.png[ExampleWithCredentials,900]

==== Blue Ocean View:
image::docs/static/ExampleWithCredentialsBlueOcean.png[ExampleWithCredentialsBlueOcean,900]

== Maintainers

Expand Down
Binary file modified docs/static/ExampleWithCredentials.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/ExampleWithCredentialsBlueOcean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Naresh Rayapati
*/
public class ExecuteCommandStep extends BasicSSHStep {
public class CommandStep extends BasicSSHStep {

private static final long serialVersionUID = 7492916747486604582L;

Expand All @@ -30,7 +30,7 @@ public class ExecuteCommandStep extends BasicSSHStep {
private boolean sudo = false;

@DataBoundConstructor
public ExecuteCommandStep(final String command) {
public CommandStep(final String command) {
this.command = command;
}

Expand All @@ -44,7 +44,7 @@ public static class DescriptorImpl extends SSHStepDescriptorImpl {

@Override
public String getFunctionName() {
return "sshExecuteCommand";
return "sshCommand";
}

@Override
Expand All @@ -57,29 +57,29 @@ public static class Execution extends SSHStepExecution {

private static final long serialVersionUID = -5293952534324828128L;

protected Execution(final ExecuteCommandStep step, final StepContext context)
protected Execution(final CommandStep step, final StepContext context)
throws IOException, InterruptedException {
super(step, context);
}

@Override
protected Object run() throws Exception {
ExecuteCommandStep step = (ExecuteCommandStep) getStep();
CommandStep step = (CommandStep) getStep();
if (Util.fixEmpty(step.getCommand()) == null) {
throw new IllegalArgumentException("command is null or empty");
}
return getLauncher().getChannel().call(new ExecuteCommandCallable(step, getListener()));
return getLauncher().getChannel().call(new CommandCallable(step, getListener()));
}

private static class ExecuteCommandCallable extends SSHMasterToSlaveCallable {
private static class CommandCallable extends SSHMasterToSlaveCallable {

public ExecuteCommandCallable(final ExecuteCommandStep step, final TaskListener listener) {
public CommandCallable(final CommandStep step, final TaskListener listener) {
super(step, listener);
}

@Override
public Object execute() {
ExecuteCommandStep step = (ExecuteCommandStep) getStep();
CommandStep step = (CommandStep) getStep();
return getService().executeCommand(step.getCommand(), step.isSudo());
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ssh/steps/GetStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ protected Object run() throws Exception {
intoPath = ws.child(step.getInto());

if (intoPath.exists() && !step.isOverride()) {
throw new IllegalArgumentException(intoPath.getRemote() + " already exist. Please set override to true just in case.");
throw new IllegalArgumentException(
intoPath.getRemote() + " already exist. Please set override to true just in case.");
}

return getLauncher().getChannel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*
* @author Naresh Rayapati
*/
public class ExecuteScriptStep extends BasicSSHStep {
public class ScriptStep extends BasicSSHStep {

private static final long serialVersionUID = 7358533459289529723L;

@Getter
private final String script;

@DataBoundConstructor
public ExecuteScriptStep(final String script) {
public ScriptStep(final String script) {
this.script = script;
}

Expand All @@ -40,7 +40,7 @@ public static class DescriptorImpl extends SSHStepDescriptorImpl {

@Override
public String getFunctionName() {
return "sshExecuteScript";
return "sshScript";
}

@Override
Expand All @@ -53,14 +53,14 @@ public static class Execution extends SSHStepExecution {

private static final long serialVersionUID = 6008070200393301960L;

protected Execution(final ExecuteScriptStep step, final StepContext context)
protected Execution(final ScriptStep step, final StepContext context)
throws IOException, InterruptedException {
super(step, context);
}

@Override
protected Object run() throws Exception {
ExecuteScriptStep step = (ExecuteScriptStep) getStep();
ScriptStep step = (ScriptStep) getStep();
FilePath ws = getContext().get(FilePath.class);
assert ws != null;
FilePath path;
Expand All @@ -79,14 +79,14 @@ protected Object run() throws Exception {
}

return getLauncher().getChannel()
.call(new ExecuteScriptCallable(step, getListener(), path.getRemote()));
.call(new ScriptCallable(step, getListener(), path.getRemote()));
}

private static class ExecuteScriptCallable extends SSHMasterToSlaveCallable {
private static class ScriptCallable extends SSHMasterToSlaveCallable {

private final String script;

public ExecuteScriptCallable(final ExecuteScriptStep step, final TaskListener listener,
public ScriptCallable(final ScriptStep step, final TaskListener listener,
final String script) {
super(step, listener);
this.script = script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.powermock.modules.junit4.PowerMockRunner;

/**
* Unit test cases for ExecuteCommandStepTest class.
* Unit test cases for CommandStep class.
*
* @author Naresh Rayapati
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ExecuteCommandStepTest.class, SSHService.class})
public class ExecuteCommandStepTest {
@PrepareForTest({CommandStepTest.class, SSHService.class})
public class CommandStepTest {

@Mock
TaskListener taskListenerMock;
Expand All @@ -49,7 +49,7 @@ public class ExecuteCommandStepTest {
@Mock
Launcher launcherMock;

ExecuteCommandStep.Execution stepExecution;
CommandStep.Execution stepExecution;

@Before
public void setup() throws IOException, InterruptedException {
Expand All @@ -71,8 +71,8 @@ public void setup() throws IOException, InterruptedException {

@Test
public void testWithEmptyCommandThrowsIllegalArgumentException() throws Exception {
final ExecuteCommandStep step = new ExecuteCommandStep("");
stepExecution = new ExecuteCommandStep.Execution(step, contextMock);
final CommandStep step = new CommandStep("");
stepExecution = new CommandStep.Execution(step, contextMock);

// Execute and assert Test.
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
Expand All @@ -83,10 +83,10 @@ public void testWithEmptyCommandThrowsIllegalArgumentException() throws Exceptio

@Test
public void testSuccessfulExecuteCommand() throws Exception {
final ExecuteCommandStep step = new ExecuteCommandStep("ls -lrt");
final CommandStep step = new CommandStep("ls -lrt");

// Since SSHService is a mock, it is not validating remote.
stepExecution = new ExecuteCommandStep.Execution(step, contextMock);
stepExecution = new CommandStep.Execution(step, contextMock);

// Execute Test.
stepExecution.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import org.powermock.modules.junit4.PowerMockRunner;

/**
* Unit test cases for ExecuteScriptStep class.
* Unit test cases for ScriptStep class.
*
* @author Naresh Rayapati
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ExecuteScriptStepTest.class, SSHService.class, FilePath.class})
public class ExecuteScriptStepTest {
@PrepareForTest({ScriptStepTest.class, SSHService.class, FilePath.class})
public class ScriptStepTest {

final String scriptName = "test.sh";

Expand All @@ -54,7 +54,7 @@ public class ExecuteScriptStepTest {
@Mock
FilePath filePathMock;

ExecuteScriptStep.Execution stepExecution;
ScriptStep.Execution stepExecution;

@Before
public void setup() throws IOException, InterruptedException {
Expand Down Expand Up @@ -82,8 +82,8 @@ public void setup() throws IOException, InterruptedException {

@Test
public void testWithEmptyCommandThrowsIllegalArgumentException() throws Exception {
final ExecuteScriptStep step = new ExecuteScriptStep("");
stepExecution = new ExecuteScriptStep.Execution(step, contextMock);
final ScriptStep step = new ScriptStep("");
stepExecution = new ScriptStep.Execution(step, contextMock);

// Execute and assert Test.
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
Expand All @@ -94,10 +94,10 @@ public void testWithEmptyCommandThrowsIllegalArgumentException() throws Exceptio

@Test
public void testSuccessfulExecuteScript() throws Exception {
final ExecuteScriptStep step = new ExecuteScriptStep(scriptName);
final ScriptStep step = new ScriptStep(scriptName);

// Since SSHService is a mock, it is not validating remote.
stepExecution = new ExecuteScriptStep.Execution(step, contextMock);
stepExecution = new ScriptStep.Execution(step, contextMock);

// Execute Test.
stepExecution.run();
Expand Down

0 comments on commit 72cd0a3

Please sign in to comment.