drone支持PHP
加密变量设置3种方式
PASSWORD 123456 # 变量设置
SSH_KEY ${cat /path/to/.ssh/id_rsa} # 命令返回值
SSH_KEY @/path/to/.ssh/id_rsa # 文件内容
原理: 将script中的每个语句通过 && 拼接为一条语句
- 多个子项之间用 && 连接
- 每个子项之间不能用 ;
# - export DRONE_COMMIT_MESSAGE=${DRONE_COMMIT_MESSAGE}
- TARGET=/docker/tomcat/webapps/${DRONE_REPO_NAME}/ ;
echo "$TARGET";
export DB_HOST=mysql;
export DB_NAME=${DRONE_REPO_NAME};
export DB_USER=lybb;
export DB_PASS="yourpassword"
# for f in `echo "$DRONE_COMMIT_MESSAGE" | sed 's/.*upgrade \(.*sql\).*/\1/'` ; do if [ -e $TARGET/$f ]; then echo $f; fi; done
# - sed -i "s|^jdbc.url=jdbc:mysql.*|jdbc.url=jdbc:mysql://mysql:3306/${DRONE_REPO_NAME}?useUnicode=true\&characterEncoding=UTF-8|g" $TARGET/WEB-INF/classes/jeesite.properties
# - sed -i "s|^jdbc.username=.*|jdbc.username=$DB_USER|g" $TARGET/WEB-INF/classes/jeesite.properties
# - sed -i "s|^jdbc.password=.*|jdbc.password=${DB_PASS}|g" ${TARGET}/WEB-INF/classes/jeesite.properties
- PORT=10000 ; docker rm -f tomcat ; docker run --restart=always -d --name tomcat -p $PORT:8080 --link mariadb:mysql -v /docker/tomcat/webapps/:/usr/local/tomcat/webapps/ -v /docker/tomcat/logs:/usr/local/tomcat/logs rinetd/tomcat:8.5
# 这里脚本是在远程机器/root目录上执行
drone 0.6
Name: "ssh-key",
Usage: "private ssh key",
EnvVar: "PLUGIN_SSH_KEY,PLUGIN_KEY,SSH_KEY
ssh-key 自动转换为PLUGIN_SSH_KEY
此外又重新定义了PLUGIN_KEY,SSH_KEY
与PLUGIN_SSH_KEY
等价
ssh:
image: appleboy/drone-ssh
host: demo.linyibr.com
# username: root
# password: ${SSH_PASSWORD}
# ssh-key: ${SSH_KEY}
port: 222
script:
- echo $SSH_PASSWORD
- echo ${SSH_PASSWORD}
- echo $${SSH_PASSWORD}
secrets: [ ssh_password,SSH_KEY ]
# drone secret add --repository linyibr/zhongzhenghuijin --image=appleboy/drone-ssh --name SSH_KEY --value @/home/ubuntu/.ssh/id_rsa
drone 0.5
drone-plugins/drone-ssh: Drone plugin for executing remote ssh commands
The following parameters are used to configure the plugin:
host - address or IP of the remote machine
port - port to connect to on the remote machine
user - user to log in as on the remote machine
key - private SSH key for the remote machine
sleep - sleep for seconds between host connections
timeout - timeout for the tcp connection attempt
script - list of commands to execute
The following secret values can be set to configure the plugin.
SSH_HOST - corresponds to host
SSH_PORT - corresponds to port
SSH_USER - corresponds to user
SSH_KEY - corresponds to key
SSH_SLEEP - corresponds to sleep
SSH_TIMEOUT - corresponds to timeout
ssh:
image: plugins/ssh
host: [ qubuluo.com ]
user: root
port: 22
sleep: 5
script:
- echo hello >word.txt
- echo world
每次修改.drone.yml 需要重新签名
drone secrets add --image=busybox --image=busybox:* octocat/hello-world SSH_KEY @/path/to/.ssh/id_rsa
export DRONE_SERVER=http://kbook.org
export DRONE_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoicmluZXRkIiwidHlwZSI6InVzZXIifQ.0ZFhdVjrBHert1yuWBk3QFO9sKVm4iPzjTkr1l024c8drone secret add --image=plugins/ssh rinetd/drone-with-go SSH_KEY @/home/ubuntu/.ssh/id_rsa
drone sign rinetd/drone-with-go
https://github.com/appleboy/drone-ssh/blob/master/main.go
Use the SSH plugin to execute commands on a remote server. The below pipeline configuration demonstrates simple usage:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
password: 1234
port: 22
script:
- echo hello
- echo world
Example configuration in your .drone.yml file for multiple hosts:
pipeline:
ssh:
image: appleboy/drone-ssh
host:
- - foo.com
- - bar.com
username: root
password: 1234
port: 22
script:- echo hello
- echo world
- echo hello
Example configuration for login with user private key:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
- password: 1234
- key: ${DEPLOY_KEY}
port: 22
script:- echo hello
- echo world
- echo hello
Example configuration for login with file path of user private key:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
- password: 1234
- key_path: ./deploy/key.pem
port: 22
script:- echo hello
- echo world
- echo hello
Example configuration for command timeout (unit: second), default value is 60 seconds:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
password: 1234
port: 22
- command_timeout: 10
script:- echo hello
- echo world
- echo hello
Example configuration for execute commands on a remote server using `SSHProxyCommand`:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
port: 22
key: ${DEPLOY_KEY}
script:
- echo hello
- echo world
- proxy_host: 10.130.33.145
- proxy_user: ubuntu
- proxy_port: 22
- proxy_key: ${PROXY_KEY}
Example configuration for success build:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
password: 1234
port: 22
script:
- echo hello
- echo world
- when:
- status: success
Example configuration for tag event:
pipeline:
ssh:
image: appleboy/drone-ssh
host: foo.com
username: root
password: 1234
port: 22
script:
- echo hello
- echo world
- when:
- status: success
- event: tag
Parameter Reference
host
target hostname or IP
port
ssh port of target host
username
account for target host user
password
password for target host user
key
plain text of user private key
key_path
key path of user private key
script
execute commands on a remote server
timeout
Timeout is the maximum amount of time for the TCP connection to establish.
command_timeout
Command timeout is the maximum amount of time for the execute commands, default is 60 secs.
proxy_host
proxy hostname or IP
proxy_port
ssh port of proxy host
proxy_username
account for proxy host user
proxy_password
password for proxy host user
proxy_key
plain text of proxy private key
proxy_key_path
key path of proxy private key