SSH Deployment task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017

Use this task in a build or release pipeline to run shell commands or a script on a remote machine using SSH. This task enables you to connect to a remote machine using SSH and run commands or a script.

Note

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, run and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.

Prerequisites

  • The task supports use of an SSH key pair to connect to the remote machine(s).
  • The public key must be pre-installed or copied to the remote machine(s).

YAML snippet

# SSH
# Run shell commands or a script on a remote machine using SSH
- task: SSH@0
  inputs:
    sshEndpoint: 
    #runOptions: 'commands' # Options: commands, script, inline
    #commands: # Required when runOptions == Commands
    #scriptPath: # Required when runOptions == Script
    #inline: # Required when runOptions == Inline
    #args: # Optional
    #failOnStdErr: true # Optional

Arguments

Argument Description
SSH endpoint The name of an SSH service connection containing connection details for the remote machine. The hostname or IP address of the remote machine, the port number, and the user name are required to create an SSH service connection.
- The private key and the passphrase must be specified for authentication.
- A password can be used to authenticate to remote Linux machines, but this is not supported for macOS or Windows systems.
Run Choose to run either shell commands or a shell script on the remote machine.
Commands The shell commands to run on the remote machine. This parameter is available only when Commands is selected for the Run option. Enter each command together with its arguments on a new line of the multi-line textbox. To run multiple commands together, enter them on the same line separated by semicolons. Example: cd /home/user/myFolder;build

NOTE: Each command runs in a separate process. If you want to run a series of commands that are interdependent (for example, changing the current folder before executing a command) use the Inline Script option instead.
Shell script path Path to the shell script file to run on the remote machine. This parameter is available only when Shell script is selected for the Run option.
Arguments The arguments to pass to the shell script. This parameter is available only when Shell script is selected for the Run option.
Advanced - Fail on STDERR If this option is selected (the default), the build will fail if the remote commands or script write to STDERR.
Control options See Control options

See also

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

What key formats are supported for the SSH tasks?

The Azure Pipelines SSH tasks use the Node.js ssh2 package for SSH connections. Ensure that you are using the latest version of the SSH tasks. Older versions may not support the OpenSSH key format.

If you run into an "Unsupported key format" error, then you may need to add the -m PEM flag to your ssh-keygen command so that the key is in a supported format.

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.