Drone的一些使用
文章目录
1. CLI Reference
1.1 Configuration
在Drone图形界面登陆后,User settings中存在Personal Token、API和CLI使用示例以及
Configure your Drone server address:
export DRONE_SERVER=http://drone.mycompany.com
Configure your Drone personal token:
export DRONE_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
2. secret
2.1 可以在repo界面添加
kind: pipeline
name: default
steps:
- name: build
image: alpine
environment:
USERNAME:
from_secret: docker_username
PASSWORD:
from_secret: docker_password
2.2 通过CLI工具加密
$ drone -v
drone version 1.2.0
# drone encrypt [command options] <repo/name> <string>
$ drone encrypt octocat/hello-world username
hl3v+FODjduX0UpXBHgYzPzVTppQblg51CVgCbgDk4U=
kind: pipeline
name: default
steps:
- name: build
image: alpine
environment:
USERNAME:
from_secret: username
---
kind: secret
name: username
data: hl3v+FODjduX0UpXBHgYzPzVTppQblg51CVgCbgDk4U=
...
2.3 通过CLI工具添加到repo
# drone secret
# drone secret add [command options] [repo/name]
$ drone secret add --name usrname --data letitia letitia/albert_zh
$ drone secret rm --name usrname letitia/albert_zh
2.4 用于SSH Pipeline中的server配置
server:
host:
from_secret: host
user:
from_secret: username
password:
from_secret: password
2.5用于environment中的变量
steps:
- name: build
commands:
- docker login -u $USERNAME -p $PASSWORD
- docker build -t hello-world .
- docker push hello-world
environment:
PASSWORD:
from_secret: password
USERNAME:
from_secret: username
3. docker-in-docker
In the below example we demonstrate a pipeline that launches a Docker service container (Docker-in-Docker). The service container is run in privileged mode. For security reasons, only trusted repositories can enable privileged mode.
---
kind: pipeline
name: default
steps:
- name: test
image: docker:dind
volumes:
- name: dockersock
path: /var/run
commands:
- sleep 5 # give docker enough time to start
- docker ps -a
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}
需要注意的是:需要是trusted仓库(挂载绝对路径),可以在图形界面Settings中设置,如果没有这一选项的话,意味着在启动Drone时没有将当前登录用户设置为管理员,详见
4. 跳过CI构建
GitLab可以在git push --push-option=<push_option>
通过选项跳过CI构建:
对于Drone,在提交的commit message中如果包含 [CI SKIP]
字段,会跳过CI构建