参考:
https://blog.csdn.net/hxpjava1/article/details/78514999 (简单操作)
https://blog.csdn.net/wh211212/article/details/72627803 (详细操作)
https://www.cnblogs.com/cnundefined/p/7095368.html (gitlab、gitlab-CI、runner的关系)
1、工程代码准备:
gitlab上新建root3组,新建print123工程,工程根目录下配置yml文件.gitlab-ci.yml
gitlab上新建gitlab-runner账号,建立和服务器的ssh免密登录。
2、yml文件(gitlab代码上):
stages:
- deploy
deploy:
stage: deploy
script:
- deploy root3 print123
only:
- master
tags:
- shell
3、在bin文件夹中定义deploy脚本文件(Linux上):解释:https://www.jianshu.com/p/df433633816b
#!/bin/bash
if [ $# -ne 2 ]
then
echo "arguments error!"
exit 1
else
deploy_path="/var/www/$1/$2"
if [ ! -d "$deploy_path" ]
then
project_path="[email protected]:"$1/$2".git"
git clone $project_path $deploy_path
else
cd $deploy_path
git pull
fi
fi
4、runner注册:
gitlab-ci-multi-runner register # 注册一个新的runner
延伸:
gitlab-ci-multi-runner status
gitlab-ci-multi-runner stop
gitlab-ci-multi-runner start
gitlab-ci-multi-runner verify # 查看所有runner
gitlab-ci-multi-runner list # 查看所有runner
gitlab-runner verify --delete # 删除无效的runner
注册用到内容:
http://10.2.3.4:8881/ # 在gitlab上查询
Juyx-L5433amkQKSo2XQ # 在gitlab上查询
deploy_description5
shell # tags要和yml文件中的tags保持一致
true
回车
5、修改print123中的文件,push提交,在gitlab的pipeline中观察是否pass