ssh远程执行shell

单机

- name: ssh commands
  image: appleboy/drone-ssh
  settings:
    host: foo.com
    username: root
    password: 1234
    port: 22
    script:
      - echo hello
      - echo world

多个主机的示例配置

  - name: ssh commands
    image: appleboy/drone-ssh
    settings:
      host:
+       - foo.com
+       - bar.com
      username: root
      password: 1234
      port: 22
        command_timeout: 2m 
        #命令超时的示例配置,默认值为 60 秒:
      script:
      - echo hello
      - echo world

ssh 密钥的示例配置

  - name: ssh commands
    image: appleboy/drone-ssh
    settings:
      host: foo.com
      username: root
      port: 22
+     key:
+       from_secret: ssh_key
      script:
        - echo hello
        - echo world
SCP传输文件
- name: scp files
  image: appleboy/drone-scp
  settings:
    host: 120.77.207.116
    username: root
    password: 
      from_secret: ssh_password
    port: 22
    target: /tmp
    #tmp目录是远程主机的
    source: ./mysql-db
    #需要传输的文件夹,当前目录

多台主机

  - name: scp files
    image: appleboy/drone-scp
    settings:
      host:
        - example1.com
        - example2.com
      user: ubuntu
      port: 22
-     password: 1234
+     password:
+       from_secret: ssh_password
      target: /home/deploy/web
      source:
        - release/*.tar.gz

完整pipeline

kind: pipeline
type: kubernetes
name: default
steps:
#- name: rsync
  #image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:rsync
  #image: drillster/drone-rsync
    #hosts: 120.77.207.116
    #key: 
      #from_secret: ssh-key
    #source: ./mysql-db
    #target: /tmp
    #script:
      #- ls -l /tmp

- name: scp files
  #image: appleboy/drone-scp
  image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:scp
  settings:
    host: 120.77.207.116
    username: root
    password: 
      from_secret: ssh_password
    port: 22
    target: /tmp
    source: ./mysql-db


- name: ssh commands
  #iamge: appleboy/drone-ssh:latest
  image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:ssh
  settings:
    host: 120.77.207.116
    username: root
    password: 
      from_secret: ssh_password
    port: 22
    script:
      - ls -l /tmp/mysql-db

官网

Logo

一站式 AI 云服务平台

更多推荐