SSH Plugin
The plugin provides functionality to execute commands via Secure Shell (SSH) connection protocol.
Installation
-
Copy the below line to
dependencies
section of the projectbuild.gradle
fileExample 1. build.gradleimplementation(group: 'org.vividus', name: 'vividus-plugin-ssh', version: '0.5.11')
-
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 |
---|---|---|---|
|
<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 |
|
|
|
Allocate a Pseudo-Terminal |
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 |
|
|
<string> |
The public key |
|
|
<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 |
---|---|---|---|
|
<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 |
|
|
|
Allocate a Pseudo-Terminal |
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 |
|
|
<string> |
The public key |
|
|
<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:SSH
orSFTP
.Table 1. The list of the supported SFTP
commandsCommand Description cd path
Change remote directory to
path
get remote-path
Download file
ls [path]
Display remote directory listing (optionally directory
path
can be specified)mkdir path
Create remote directory
pwd
Display remote working directory
rmdir path
Remove remote directory
rm path
Remove 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