- 服務端安裝git
-
- yum install git
- git - -version 查看git版本
- git config —global user.name “myname"
- git config —global user.email “myemail@qq.com"
- ssh-keygen生成公鑰
- 寶塔安裝webHook軟件
-
- 碼雲設置項目webhook
-
#!/bin/bash
echo ""
#輸出當前時間
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#判斷寶塔WebHook參數是否存在
if [ ! -n "$1" ];
then
echo "param參數錯誤"
echo "End"
exit
fi
#git項目路徑
gitPath="/www/wwwroot/xxxxxx"
#git 網址
gitHttp="git@gitee.com:xxxxxx/xxxxxx.git"
echo "Web站點路徑:$gitPath"
#判斷項目路徑是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
#判斷是否存在git目錄
if [ ! -d ".git" ]; then
echo "在該目錄下克隆 git"
git clone $gitHttp gittemp
mv gittemp/.git .
rm -rf gittemp
fi
#拉取最新的項目文件
git reset --hard origin/master
git pull
#設置目錄權限
chown -R www:www $gitPath
echo "End"
exit
else
echo "該項目路徑不存在"
echo "End"
exit
fi