logo
2
1
WeChat Login
The repository has been archived and is now in read-only mode.

SSH

Execute commands on remote host via SSH.

Parameter Description

  • host: Target machine hostname or IP
  • port: Target host SSH port
  • protocol: IP protocol to use: can be tcp, tcp4, or tcp6
  • username: Target host username
  • password: Target host password
  • key: Private key text
  • key_path: Private key path
  • passphrase: Private key passphrase
  • script: Commands to execute on remote server
  • script_stop: Stop executing subsequent commands when a command fails
  • timeout: Maximum time for SSH connection establishment, default is 30 seconds
  • command_timeout: Maximum time for command execution, default is 10 minutes
  • proxy_host: Proxy hostname or IP
  • proxy_port: Proxy host SSH port
  • proxy_protocol: IP protocol for proxy: can be tcp, tcp4, or tcp6
  • proxy_username: Proxy host username
  • proxy_password: Proxy host password
  • proxy_key: Proxy host private key plain text
  • proxy_key_path: Path to proxy host private key
  • proxy_passphrase: Proxy host private key passphrase

Usage in Cloud Native Build

Simple 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

About

No description, topics, or website provided.
380.00 KiB
2 forks1 stars1 branches0 TagREADMEMIT license
Language
Markdown94.4%
License4%
SVG1.4%
Dockerfile0.2%