SSH Plugin
The plugin provides functionality to execute commands via Secure Shell (SSH) connection protocol.
Installation
-
Copy the below line to
dependenciessection of the projectbuild.gradlefilePlease make sure to use the same version for all VIVIDUS dependencies. Example 1. build.gradleimplementation('org.vividus:vividus-plugin-ssh') -
If the project was imported to the IDE before adding new dependency, re-generate the configuration files for the used IDE and then refresh the project in the used IDE.
Properties
It’s allowed to configure unlimited number of SSH connections via mechanism of the dynamic properties. The properties prefix example is:
ssh.server.my-server
where my-server is a key used to refer SSH connection in the steps. The key is defined by users, it must be unique and can’t contain dots.
| The properties marked with bold are mandatory. |
| Name | Acceptable values | Default | Description |
|---|---|---|---|
|
|
|
Allocate a Pseudo-Terminal |
|
<string> |
The name of the user logging in |
|
|
hostname or IP |
The remote host |
|
|
0..65535 |
The remote port (The standard TCP port for SSH is 22) |
|
|
|
|
Enable forwarding of the authentication agent connection |
The following properties are used only for the password-based authentication |
|||
|
<string> |
The password |
|
The following properties are used only for the public key authentication |
|||
|
<string> |
The private key, must not be used along with |
|
|
<string> |
The public key, must not be used along with |
|
|
<string> |
The path to a private key file on the filesystem, must not be used along with |
|
|
<string> |
The path to a public key file on the filesystem, must not be used along with |
|
|
<string> |
The passphrase for the private key |
|
The following properties are not applicable for SFTP |
|||
|
|
|
In common *nix OpenSSH server:
With less common SSH servers, the difference can be even more significant. Some servers may not even support one of the channels. It is also quite common that they seemingly support both, but one of them (typically the |
Steps
Configure dynamic SSH connection
Creates a new dynamic SSH connection from the provided parameters, the connection is available only within the story creating the connection.
When I configure SSH connection with key `$connectionKey` and parameters:$connectionParameters
-
$connectionKey- The key to assign to the creating SSH connection. In case if the key conflicts with a global connection key, the dynamic connection will take precedence within the story. -
$connectionParameters- The ExamplesTable with SSH connection parameters.The parameters marked with bold are mandatory.
| Name | Acceptable values | Default | Description |
|---|---|---|---|
|
|
|
Allocate a Pseudo-Terminal |
|
<string> |
The name of the user logging in |
|
|
hostname or IP |
The remote host |
|
|
0..65535 |
The remote port (The standard TCP port for SSH is 22) |
|
|
|
|
Enable forwarding of the authentication agent connection |
The following parameters are used only for the password-based authentication |
|||
|
<string> |
The password |
|
The following parameters are used only for the public key authentication |
|||
|
<string> |
The private key, must not be used along with |
|
|
<string> |
The public key, must not be used along with |
|
|
<string> |
The path to a private key file on the filesystem, must not be used along with |
|
|
<string> |
The path to a public key file on the filesystem, must not be used along with |
|
|
<string> |
The passphrase for the private key |
|
The following parameters are not applicable for SFTP |
|||
|
|
|
In common *nix OpenSSH server:
With less common SSH servers, the difference can be even more significant. Some servers may not even support one of the channels. It is also quite common that they seemingly support both, but one of them (typically the |
When I configure SSH connection with key `my-connection` and parameters:
|username |host |port|password|
|admin |10.10.10.10|22 |Pa$$w0rd|
Execute commands
Retrieves SSH connection parameters by key, opens SSH session and executes commands remotely via the specified protocol.
When I execute commands `$commands` on $connectionKey over $protocol
-
$commands- Semicolon-separated commands to execute. -
$connectionKey- The SSH connection key matching any of configured ones. -
$protocol- The protocol of execution:SSHorSFTP.Table 1. The list of the supported SFTPcommandsCommand Description cd pathChange remote directory to
pathget remote-pathDownload file
ls [path]Display remote directory listing (optionally directory
pathcan be specified)mkdir pathCreate remote directory
pwdDisplay remote working directory
rmdir pathRemove remote directory
rm pathRemove remote file
When I execute commands `cd /; pwd` on my-host over SSH
When I execute commands `cd /Users` on my-host over SFTP
Execute commands via SFTP and save the result
Retrieves SSH connection parameters by key, opens SSH session, executes SFTP commands remotely and saves the result of the commands to the variable.
When I execute commands `$commands` on $connectionKey over SFTP and save result to $scopes variable `$variableName`
-
$commands- Semicolon-separated SFTP commands to execute.It’s allowed to combine any SFTP commands, but at least one of them should return result. SFTP commands returning results are:
-
get remote-path -
ls [path] -
pwd
-
-
$connectionKey- The SSH connection key matching any of configured ones. -
$variableName- The name of the variable to save the SFTP commands execution result.
When I execute commands `get remote-file.txt` on my-host over SFTP and save result to scenario variable `file-content`
Create a file via SFTP
Retrieves SSH connection parameters by key, opens SSH session and creates file with the given content at the provided remote destination.
When I create file with content `$content` at path `$destination` on $connectionKey over SFTP
-
$content- The content of the file to create. -
$destination- The remote file destination. -
$connectionKey- The SSH connection key matching any of configured ones.
When I create file with content `hello world!` at path `remote-file.txt` on my-host over SFTP
Copy a file via SFTP
Retrieves SSH connection parameters by key, opens SSH session and copies the local file to the remote destination.
When I copy local file located at `$filePath` to path `$destination` on $connectionKey over SFTP
-
$filePath- The path of the file to copy. -
$destination- The remote file destination. -
$connectionKey- The SSH connection key matching any of configured ones.
When I copy local file located at `local-file.txt` to path `remote-file.txt` on my-host over SFTP
Port forwarding
Opens an SSH session and forwards a local port to a remote host and port using the provided parameters. All the opened SSH sessions will be closed after all the batches are executed.
When I forward port through SSH using parameters:$parameters
-
$parameters- The ExamplesTable with SSH port forwarding and connection parameters.The parameters marked with bold are mandatory.
| Name | Acceptable values | Default | Description |
|---|---|---|---|
|
0..65535 |
The local TCP port to bind on the client machine. Incoming connections to this port are sent through the SSH tunnel |
|
|
0..65535 |
The TCP port on the |
|
|
hostname or IP |
The target host (reachable from the SSH server) to which the forwarded traffic should be delivered. This can be an internal host not directly accessible from the client :connection-parameters-prefix: |
|
|
<string> |
The name of the user logging in |
|
|
hostname or IP |
The remote host |
|
|
0..65535 |
The remote port (The standard TCP port for SSH is 22) |
|
|
|
|
Enable forwarding of the authentication agent connection |
The following parameters are used only for the password-based authentication |
|||
|
<string> |
The password |
|
The following parameters are used only for the public key authentication |
|||
|
<string> |
The private key, must not be used along with |
|
|
<string> |
The public key, must not be used along with |
|
|
<string> |
The path to a private key file on the filesystem, must not be used along with |
|
|
<string> |
The path to a public key file on the filesystem, must not be used along with |
|
|
<string> |
The passphrase for the private key |
|