开始炼狱般的折腾:一种奇怪的Gitee自动构建实现脚本

现状是我们需要将Gitee的代码拉到服务器上进行自动部署。Gitee的webhook也能通知到我们的服务器url,但是webshell执行权限卡住了。
于时采用了一种曲线救国的方式,实现自动部署。这么晚了,直接帖代码好了。
#!/bin/bash

for i in {1..12}
do
echo $i
echo “检测git更新”

if [ -f “/www/wwwroot/www.yue.ma/yuemagit.lock” ];then
echo “发现git更新”
if [ -f “/www/wwwroot/www.yue.ma/yuemagit.runing” ];then
echo “已有作业在执行,跳过本次执行”
else
echo “抢锁执行”
touch /www/wwwroot/www.yue.ma/yuemagit.runing
cd /www/yuemagit/yuema/server
git fetch –all
git reset –hard origin/master
git pull
echo “git拉取完成”
\cp -r /www/yuemagit/yuema/server/* /www/wwwroot/www.yue.ma/
echo “部署完成”
rm -rf /www/wwwroot/www.yue.ma/yuemagit.lock
echo “释放部署锁完成”
rm -rf /www/wwwroot/www.yue.ma/yuemagit.runing
echo “释放部署执行锁完成”
fi
else
echo “未检测到git更新”
fi

sleep 5

done

echo “本周期操作检测完,等下一个周期”
if [ ! -f “/www/wwwroot/www.yue.ma/yuemagit.runing” ];then
rm -rf /www/wwwroot/www.yue.ma/yuemagit.runing
fi
技术岛是首发地址,每天折腾一点点!

此条目发表在未分类分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注