Execute commands on remote host via SSH.
host: Target machine hostname or IPport: Target host SSH portprotocol: IP protocol to use: can be tcp, tcp4, or tcp6username: Target host usernamepassword: Target host passwordkey: Private key textkey_path: Private key pathpassphrase: Private key passphrasescript: Commands to execute on remote serverscript_stop: Stop executing subsequent commands when a command failstimeout: Maximum time for SSH connection establishment, default is 30 secondscommand_timeout: Maximum time for command execution, default is 10 minutesproxy_host: Proxy hostname or IPproxy_port: Proxy host SSH portproxy_protocol: IP protocol for proxy: can be tcp, tcp4, or tcp6proxy_username: Proxy host usernameproxy_password: Proxy host passwordproxy_key: Proxy host private key plain textproxy_key_path: Path to proxy host private keyproxy_passphrase: Proxy host private key passphraseSimple example:
main:
push:
- stages:
- name: echo file
image: tencentcom/ssh
settings:
host: xx.xx.xx.xxx
username: root
password: xxxx
port: 22
script:
- echo hello world
- echo test > ~/test.txt
Example with multiple target machines:
main:
push:
- stages:
- name: echo file
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xxx
- xx.xx.xx.xxx
username: root
password: xxxx
port: 22
script:
- echo hello world
- echo test > ~/test.txt
Example with host including port:
main:
push:
- stages:
- name: echo file
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xxx:22
username: root
password: xxxx
script:
- echo hello world
- echo test > ~/test.txt
Example with command timeout:
main:
push:
- stages:
- name: echo file
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xx:22
username: root
password: xxxx
command_timeout: 10s
script:
- sleep 15s
Example of referencing password from key repository configuration file:
# Key repository env.yml
PAASWORD: xxxx
# Declare which plugin tasks with specific images can reference this configuration file
allow_images:
- tencentcom/ssh
# Declare which pipeline repositories can reference this configuration file
allow_slugs:
- group/repo
main:
push:
- stages:
- name: echo file
# Reference key repository configuration file
imports: https://xxx/group/secret-repo/-/blob/main/env.yml
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xxx:22
username: root
# Reference variable from key repository configuration file
password: $PAASWORD
script:
- echo hellworld
Example of referencing SSH key from key repository configuration file:
# Key repository env.yml
SSH_KEY: |
-----BEGIN OPENSSH PRIVATE KEY-----
xxx
-----END OPENSSH PRIVATE KEY-----
# Declare which plugin tasks with specific images can reference this configuration file
allow_images:
- tencentcom/ssh
# Declare which pipeline repositories can reference this configuration file
allow_slugs:
- group/repo
main:
push:
- stages:
- name: echo file
# Reference key repository configuration file
imports: https://xxx/group/secret-repo/-/blob/main/env.yml
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xxx:22
username: root
key: $SSH_KEY
script:
- echo hellworld
Example of stopping script execution after failure:
main:
push:
- stages:
- name: echo file
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xxx:22
username: root
password: xxxx
script_stop: true
script:
- echo test1 > ~/test.txt
- echo1 hellworld
# This command will not execute
- echo test2 > ~/test.txt
Example of SSH key with passphrase:
main:
push:
- stages:
- name: echo file
# Reference key repository configuration file
imports: http://xxx/-group/secret-repo/-/blob/main/env.yml
image: tencentcom/ssh
settings:
host:
- xx.xx.xx.xxx:22
username: root
key: $SSH_KEY_PHRASE
passphrase: xxx
script:
- echo hellworld
Execute startup command on target machine via SSH plugin and JumpServer
main:
push:
- imports: https://cnb.cool/examples/secrets/-/blob/main/springboot-maven-docker-jumpserver-config.yml
stages:
- name: Execute startup command on target machine via SSH plugin and JumpServer
image: tencentcom/ssh
settings:
# Intranet machine IP
host:
- ${REMOTE_HOST}
username: ${REMOTE_USERNAME}
key: ${REMOTE_KEY}
port: ${REMOTE_PORT}
command_timeout: 2m
# Public network machine IP
proxy_host: ${PROXY_HOST}
proxy_port: ${PROXY_PORT}
proxy_protocol: tcp
proxy_username: ${PROXY_USERNAME}
proxy_key: ${PROXY_KEY}
script: |
hostname