Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The SSH Run Script Action is used action is a premium action which used to run scripts on an SSH server. The action can either run an entire script or a list of commands. All output is written to the build log as it is received from the host. 

SSH Run Script

Image RemovedImage Added

...

titleNote:

Name

A friendly name for this action (will be displayed in the actions workflow area).

Enabled

Determines if this action will be run within the relevant stage

...

.

Host Name

The URL or IPv4 address of the SSH host to connect to. The host should be accessible from all agents able to run the build containing this action. If any connection issues are detected they will appear in the build log. Action will connect and represent itself as an xterm client. In addition it will use a channel to send commands so that it can easily detect when they have been completed. If a script is

used in the action, SFTP will be used to upload the script to the host for execution. This guarantees that the script runs in the context of the host, and does not have to deal with any translation issues between the actions client and the server. Once run the script file will be removed from the SSH host. 

Port

The port number that the SSH host will be listening on. Port 22 is the default port for SSH hosts. 

Login Name

The name of the user under which all the commands will be run. The user will only be logged in for the lifetime of the action. 

Password

The password for the supplied user. This password is stored as an encrypted value within the action, and once entered will not be able to be read by those editing the action. It will also not appear in any logs. 

Run Option

Run Type

Select whether you want to specify a sequence of Commands or a Script File to run. 

Script

This text area is shown when the Commands option is selected for the Run Type. Enter a list of commands to run one after the other on the target host. When run, the Commands: The commands option allows for running of a sequence of commands in the action. The action will open a channel once connected and proceed to call each command in sequence waiting for the previous command to complete. Once all commands have been run, the channel and connection will be closed and the action will completed, returning the exitCode exit code of the last run command. 

Note: For each subsequent command to be run, the terminal must return to a shell prompt. It is suggested that this method is used only when running simple commands.

Script File

This input box is shown when the Script file option is selected for the Run Type. Enter the path to the script file.

When the action is run, the script file is uploaded to the SSH host using SFTP and placed Script: The script option allows for a script to be uploaded to the SSH host and run locally under the users account. This allows for commands to be run in the context of the SSH host and to avoid any translation issues between the actions client implementation and the host in question. The script is uploaded using SFTP, placing the file in the base directory of the logged in user. This .  The script is then updated to be executable and executed under the users account.  This requires the user to be able to write and execute files in their base directory. The script is then updated to be executable, and then executed from the users base directory. The  The action will then wait for the script to complete , and then sets before setting the Exit Code Variable to the last error code of the script. Before completing the action will remove the script file, and then close closing the channel and connection. 

Script File

The location of the script file to run. The script should be written as though it was run from the users login base directory and as the logged in user.

Script

The list of commands to run on the host. 

Convert any Windows newlines (CLRF) in script file to UNIX newlines (LF)

This is shown when the Script file option is selected for the Run Type. If this is ticked, any Windows newlines (CLRF) in script file are converted to UNIX newlines (LF).

Clean up script after run

If this is ticked, the script file will be removed after run is cleaned up.


Authentication

Image Added

Username

The username under which all the commands will be run. The user will only be logged in for the lifetime of the action.

Password

The password for the supplied user. This password is stored as an encrypted value within the action and once entered cannot be read by those editing the action. It will also not appear in any logs.

Private File

...

Key

If the host uses SSH keys, the file containing the key can be supplied here. The action supports several private key formats: PKCS  PKCS #8, OpenSSH/OpenSSL and PuTTY  OpenSSH/OpenSSL and PuTTY .ppk

PKCS #8 keys

RFC 5208 (PKCS #8) defines a private key format informally known as PKCS #8 key format. It supports several encryption algorithms (3DES is used by default). To save keys using this format, specify SshPrivateKeyFormat.Pkcs8 when calling SshPrivateKey.Save.

Encrypted ExampleSample of encrypted private key in Base64-encoded PKCS #8 format:

-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQI5yNCu9T5SnsCAggA
MBQGCCqGSIb3DQMHBAhJISTgOAxtYwSCAWDXK/a1lxHIbRZHud1tfRMR4ROqkmr4
kVGAnfqTyGptZUt3ZtBgrYlFAaZ1z0wxnhmhn3KIbqebI4w0cIL/3tmQ6eBD1Ad1
nSEjUxZCuzTkimXQ88wZLzIS9KHc8GhINiUu5rKWbyvWA13Ykc0w65Ot5MSw3cQc
w1LEDJjTculyDcRQgiRfKH5376qTzukileeTrNebNq+wbhY1kEPAHojercB7d10E
+QcbjJX1Tb1Zangom1qH9t/pepmV0Hn4EMzDs6DS2SWTffTddTY4dQzvksmLkP+J
i8hkFIZwUkWpT9/k7MeklgtTiy0lR/Jj9CxAIQVxP8alLWbIqwCNRApleSmqtitt
Z+NdsuNeTm3iUaPGYSw237tjLyVE6pr0EJqLv7VUClvJvBnH2qhQEtWYB9gvE1dS
BioGu40pXVfjiLqhEKVVVEoHpI32oMkojhCGJs8Oow4bAxkzQFCtuWB1

MIIBpjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQINGy1T4l5EpQCAggA
MBQGCCqGSIb3DQMHBAg6pbq0RezDVQSCAWDx7hriZBN1U7lYlBAQw7V0lpwn3mzL
cyUFc+tfQ9U7KYXw5PxZUobYWIrQiFXAymVFBgi+IWRyXgNwKbtUxmkavslsI3DU
Xtee+XzsgMJ1TSN/PJpfNM7/y5o1jxp6LZU88wKo43AQCSdlAu9cDgzbWaL2bBAY
MihGto6+Bs1kL4bkHsHUVNz2fcWhbwwTqN6EjxC9wbppn+3lXdFOM6T/KrvPdZqa
AjX+EoD5RIKLEVCzTjx+OLTmkdXsAuwEGlW2Kih5jdeHL5cBu8wGbCa+wH9z+OBg
k2Q2+dErX60KAk/YApXkoET/bEFm40t+UO8HfaETk907lECfFrgpUU7/7MYOwZwK
mlPdAqC6+UCi0aEN2uIZ1WV+MK7laJaeD+Co9VZgsTHz8Egg5kZXq9e43c5DVjTo
wDrJ6GtaTFJYSgrjVpv+7eAkUdsP3ChXEUpYHCU1cEZ97gcgVbtlubwE
-----END ENCRYPTED PRIVATE KEY-----

Unencrypted ExampleSample of unencrypted private key in Base64-encoded PKCS #8 format:

-----BEGIN PRIVATE KEY-----
MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEA0SC5BIYpanOv6wSm
dHVVMRa+6iw/0aJpT9/LKcZ0XYQ43P9Vwn8c46MDvFJ+Uy41FwbxT+QpXBoLlp8D
sJY/dQIDAQABAkAesoL2GwtxSNIF2YTli2OZ9RDJJv2nNAPpaZxU4YCrST1AXGPB
tFm0LjYDDlGJ448syKRpdypAyCR2LidwrVRxAiEA+YU5Zv7bOwODCsmtQtIfBfhu
6SMBGMDijK7OYfTtjQsCIQDWjvly6b6doVMdNjqqTsnA8J1ShjSb8bFXkMels941
fwIhAL4Rr7I3PMRtXmrfSa325U7k+Yd59KHofCpyFiAkNLgVAiB8JdR+wnOSQAOY
loVRgC9LXa6aTp9oUGxeD58F6VK9PwIhAIDhSxkrIatXw+dxelt8DY0bEdDbYzky
r9nicR5wDy2W

MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAqqEXkcDqDLopGKCD
mPIIgmeSnTGMHZNfzHiaizHf8ruQmbxXh95qCY4LHC5/Bx3HNkWbE7XUW0oGJLOw
LLeHswIDAQABAkBRa8ecdKr64caEiuvhCvXGjHfo7ODIqC+ZmZ9ddrI/2Dt2QdIs
Dx1sLxKoSfvC/ppyt5DcaqQTIpvv/9QBdeIBAiEAyFI7WgkwyRWko1BM15y+fqyR
sieYNEwP1D/EleWlMQECIQDaDiR163FkcqJ/9VzcVHBhVrqE9qnQcL/a2yMmJzJE
swIgFJoAaJ4RWlzTdchIXtRL8xMkWMIhsR8xcY6tVQ0tFAECIQDAcvTpAghNAAO9
bV8ssnWQ40uxKEZNygT58qg99yAdkwIhAJk67u3r0AZOSMGkXqtS3KI2oJMO8JCw
m6PS1MOl91aZ
-----END PRIVATE KEY-----

PuTTY .ppk keys

...

PuTTY

...

Example

...

:

PuTTY-User-Key-File-2: ssh-rsa

...


Encryption:

...

none
Comment: ssh-rsa-key-

...

20170905
Public-Lines:

...

2
AAAAB3NzaC1yc2EAAAADAQABAAAAQQCqoReRwOoMuikYoIOY8giCZ5KdMYwdk1/M
eJqLMd/yu5CZvFeH3moJjgscLn8HHcc2RZsTtdRbSgYks7Ast4ez
Private-Lines:

...

4
AAAAQFFrx5x0qvrhxoSK6+EK9caMd+js4MioL5mZn112sj/YO3ZB0iwPHWwvEqhJ
+8L+mnK3kNxqpBMim+//1AF14gEAAAAhAMhSO1oJMMkVpKNQTNecvn6skbInmDRM
D9Q/xJXlpTEBAAAAIQDaDiR163FkcqJ/9VzcVHBhVrqE9qnQcL/a2yMmJzJEswAA
ACEAmTru7evQBk5IwaReq1Lcojagkw7wkLCbo9LUw6X3Vpk=
Private-MAC:

...

e4378e86478e8f1cdd2fb1bbb634965104a8808c

OpenSSH/OpenSSL (SSLeay)

...

keys

OpenSSH and OpenSSL

...

Example

...

:

-----BEGIN RSA PRIVATE KEY-----

...


MIIBOwIBAAJBAKqhF5HA6gy6KRigg5jyCIJnkp0xjB2TX8x4mosx3/K7kJm8V4fe
agmOCxwufwcdxzZFmxO11FtKBiSzsCy3h7MCAwEAAQJAUWvHnHSq+uHGhIrr4Qr1
xox36OzgyKgvmZmfXXayP9g7dkHSLA8dbC8SqEn7wv6acreQ3GqkEyKb7//UAXXi
AQIhAMhSO1oJMMkVpKNQTNecvn6skbInmDRMD9Q/xJXlpTEBAiEA2g4kdetxZHKi
f/Vc3FRwYVa6hPap0HC/2tsjJicyRLMCIBSaAGieEVpc03XISF7US/MTJFjCIbEf
MXGOrVUNLRQBAiEAwHL06QIITQADvW1fLLJ1kONLsShGTcoE+fKoPfcgHZMCIQCZ
Ou7t69AGTkjBpF6rUtyiNqCTDvCQsJuj0tTDpfdWmQ==
-----END RSA PRIVATE KEY-----

...

New OpenSSH keys #

New OpenSSH format is used by OpenSSH for storing encrypted or unencrypted EcDSA and Ed25519 keys, although it supports other key algorithms as well. To save keys using this format, specify SshPrivateKeyFormat.NewOpenSsh when calling SshPrivateKey.Save.

A sample of a private key in the new OpenSSH format:

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jYmMAAAAGYmNyeXB0AAAAGAAAABAxBix87d
JvVrEotmWsbAZwAAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIPKKmhHgVw5SM8IH
uo2XalsMHXvDwBxA7vL+TG/CACK9AAAAkNWU8rq/ToxIgS2BXVJNJI8SI8qHehGmUGEmMI
A+w+bpKwhfWj/Z24DHXrtdPpeTbUT7KHODlBu+StJpN1vtW5kNSuMpE9fL+0GEIasIDsEY
9xD1sLtGAy0pMR6yzB3EW2OEZE8NoTCKJ0Xq18km8Uo1KG8naT2DeSEDzuHSP6NQWkJx5k
BmP6jMW98HAsSIQA==
-----END OPENSSH PRIVATE KEY----- 

Passphrase

 

Exit Code Variable

 

Script timeout


Passphrase

If the private key was encrypted with a passphrase it should be placed in this field. The passphrase is encrypted when stored in the database, and will not appear in any logs. 


Options

Image Added

Use UTF8 Encoding

If this is ticked, UTF8 encoding is used when communicating with the SSH server.

Character Encoding Name

Visible only if 'Use UTF8 Encoding' is not ticked.

Enter the international standard name for the encoding of the response from your SSH server. See Encoding for full list. Leave blank to use the current code page on the agent operating system.

Fail on non-zero exit code

If this is ticked, a non-zero exit code causes the action to fail.  

Ignore Exit Codes

The list of exit codes to ignore (comma-delimited).

Exit Code Variable

Select a build variable to store the last exit code received from the script or commands that were run. All commands are run through an SSH channel. After running all the commands supplied, the channel returns its exit status.

Expression variables which cannot be modified are not listed.

Continue running next command on failure

Visible only if 'Command' Run Type is selected under the 'SS Run Script' tab.

If this is ticked, the next command continues to run on failure.

Script timeout

The time in milliseconds to wait before the action should timeout when waiting for a response from the host. 

Ignore warnings

If this is ticked, any warnings logged will not mark the action with a warning status.