【Gitlab】集成自动化部署PHP代码

1、在Gitlab项目的Setting > Variables 里增加SSH_PASSWORD和SSH_USERNAME变量,分别保存服务器的登录用户名和密码;这两个变量在.gitlab-ci.yml里会用到

2、在.gitlab-ci.yml里增加以下配置,其中的serverName替换为服务器的域名或IP,deploytest为自己写的部署脚本;其他参数按需自定义

01
02
03
04
05
06
07
08
09
10
11
12
13
14
stages:
   - deploy-test
 
deploy-test:
   stage: deploy-test
   script:
     - sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no -p 22 $SSH_USERNAME@serverName "cd /data/www/deploy_test; ./deploytest master quiet"
   environment:
     name: test
   when: manual
   tags:
     - chest
   only:
     - master

以上-o StrictHostKeyChecking=no是必须的,否则会出现ERROR: Job failed: exit code 1报错;细究以下发现是gitlab里的容器第一次ssh登录服务器会出现以下提示,因为没有响应而报错。

Are you sure you want to continue connecting (yes/no)?

猜你喜欢

转载自www.cnblogs.com/thspz/p/12047938.html