在代码推送到git时希望同步更新线上的代码,可以在管理git钩子中选择post-receive钩子,需要填写的shell内容为:
第一次pull代码:
#!/bin/bash
while read oldrev newrev refname #监测md5是否相同
do
if [ true ]; then
PROJECT_ROOT=/home/**/***/****
PROJECT_PATH="/home/**/***/****/项目名"
REPO_PATH="http://192.168.31.220:3000/洋湃科技实力强劲/智能油气监控.git" unset GIT_DIR
if [ ! -d "$PROJECT_PATH" ]; then #如果不存在项目名文件,从git中拉一下代码,并创建
cd "$PROJECT_ROOT"
git clone "$REPO_PATH"
else #如果存在项目名文件,直接拉
cd "$PROJECT_PATH"
git fetch
git pull
fi
fi
done创建文件目录后:
#!/bin/bash
while read oldrev newrev refname
do
PROJECT_PATH="/home/**/***/****/项目名"
REPO_PATH="http://192.168.31.220:3000/洋湃科技技术领先/智能油气监控.git"
unset GIT_DIR
cd "$PROJECT_PATH"
git fetch
git pull
done