drone_ci脚本编写

脚本用yml编写,每个管道用—来区分,单一管道内通过-name来设定不同的步骤,每个管道内的步骤,有when设定满足执行条件.

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# build代码
kind: pipeline
type: ssh
name: 开发测试更新部署

clone:
disable: true

# 执行平台
platform:
os: linux
arch: arm

server:
host: 10.12.0.6
user: pi
password:
from_secret: passwd

# 更新代码
steps:

# 更新仓库
- name: 拉取
environment:
VARPATH: /var
REPO_URL: 10.12.0.2:3000
WORKSPACE: /workspace
PROJ_NAME: aliseochina
BRANCH: develop
GITUSR:
from_secret: git_usr
GITPASS:
from_secret: git_pass

commands:
# 初始化部分,第一次clone从仓库中
- cd $$WORKSPACE/$$PROJ_NAME
- git pull

when:
branch:
- develop

# 部署代码
- name: 部署测试站
depends_on:
- 拉取
environment:
VARPATH: /var
WORKSPACE: /workspace
PROJ_NAME: aliseochina
REMOTE_USER: ubuntu
REMOTE_HOST: 165.154.20.145
TARGET: /tmp/aliseo
EXCLUDE_FROM_FILE: 'exclude-file.txt'
commands:
- cd $$WORKSPACE/$$PROJ_NAME
# 同步代码
- rsync -ave -t -r -z --rsh=ssh --stats * --exclude-from=$$EXCLUDE_FROM_FILE $$REMOTE_USER@$$REMOTE_HOST:$$TARGET

when:
branch:
- develop

# 触发条件
trigger:
branch:
- develop
event:
- pull_request
- push

secret秘钥的添加

  • 通过网站添加

  • 通过命令添加

    • 安装drone命令
      1
      2
      3
      4
      5
      6
      7
         wget https://github.com/harness/drone-cli/releases/download/v1.5.0/drone_linux_arm.tar.gz
      tar zxvf drone_linux_arm.tar.gz
      cp drone /usr/local/bin

      # 编辑bashrc添加
      export DRONE_SERVER=http://ip:9090
      export DRONE_TOKEN=秘钥
    • 针对某个仓库添加秘钥
      1
      2
      3
      4
      drone secret add \
      --repository 仓库名称 \
      --name rsync_key \
      --data @./id_rsa