drone-ssh/README.zh-tw.md
appleboy 1dfeaffef3
docs: add Table of Contents to all language README files
- Add a Table of Contents section to the English, Simplified Chinese, and Traditional Chinese README files

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-26 22:00:28 +08:00

4.0 KiB

drone-ssh

English | 繁體中文 | 简体中文

sshlog

GitHub tag GoDoc Lint and Testing codecov Go Report Card Docker Pulls

Drone 外掛程式,可透過 SSH 在遠端主機執行指令。使用方式與可用選項請參考官方文件

注意:請將 Drone 的 image config 路徑更新為 appleboy/drone-sshplugins/ssh 已不再維護。

demo

目錄

重大變更

v1.5.0:將指令逾時參數改為 Duration 格式。設定範例如下:

pipeline:
  scp:
    image: ghcr.io/appleboy/drone-ssh
    settings:
      host:
        - example1.com
        - example2.com
      username: ubuntu
      password:
        from_secret: ssh_password
      port: 22
-     command_timeout: 120
+     command_timeout: 2m
      script:
        - echo "Hello World"

建置或下載執行檔

可於發行頁面下載預先編譯的執行檔,支援以下作業系統:

  • Windows amd64/386
  • Linux arm/amd64/386
  • macOS (Darwin) amd64/386

若已安裝 Go,可執行:

go install github.com/appleboy/drone-ssh@latest

或使用下列指令手動建置執行檔:

export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on

go test -cover ./...

go build -v -a -tags netgo -o release/linux/amd64/drone-ssh .

Docker

可使用下列指令建置 Docker 映像檔:

make docker

使用方式

於工作目錄下執行:

docker run --rm \
  -e PLUGIN_HOST=foo.com \
  -e PLUGIN_USERNAME=root \
  -e PLUGIN_KEY="$(cat ${HOME}/.ssh/id_rsa)" \
  -e PLUGIN_SCRIPT=whoami \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  ghcr.io/appleboy/drone-ssh

以檔案路徑掛載金鑰

請確認已於專案設定中啟用 trusted 模式(適用於 Drone 0.8 版本)。

trusted mode

.drone.yml 設定檔的 volumes 區段掛載私鑰:

pipeline:
  ssh:
    image: ghcr.io/appleboy/drone-ssh
    host: xxxxx.com
    username: deploy
+   volumes:
+     - /root/drone_rsa:/root/ssh/drone_rsa
    key_path: /root/ssh/drone_rsa
    script:
      - echo "test ssh"

詳情請參考 此 issue comment

設定說明

更多範例與完整設定選項請參考 DOCS.md

設定選項來源如下:

  1. 內建 drone-ssh 預設值。詳見 main.go CLI Flags
  2. PLUGIN_ENV_FILE 環境變數指定的 dotenv 檔案。
  3. .drone.yml Drone 設定檔。

後面的來源會覆蓋前面的設定。例如,.env 檔案中的 PORT 會覆蓋 main.go 的預設值。