宝塔部署项目,git推送自动更新部署
- 服务器
- 2025-12-13
- 12热度
- 0评论
1,安装宝塔webHook
#!/bin/bash
echo ""
#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#git分支名称
branch="master"
#git项目路径
gitPath="/www/wwwroot/dingsun"
#git 仓库地址
gitHttp="https://gitee.com/liaoshimin/dingsun.git"
#gitHttp="http://192.168.2.20/llh/$1.git" //多仓库的时候
echo "路径:$gitPath"
#判断项目路径是否存在
if [ -d "$gitPath" ]; then
cd $gitPath
#判断是否存在git目录
if [ ! -d ".git" ]; then
echo "在该目录下克隆 git"
sudo git clone $gitHttp gittemp
sudo mv gittemp/.git .
rm -rf gittemp
fi
#拉取最新的项目文件
sudo git reset --hard origin/$branch
#git clean -f
# 排查错误 2>&1
sudo git pull origin $branch 2>&1
echo "拉取完成"
#执行npm
#执行编译
#npm run build
#设置目录权限
chown -R www:www $gitPath
echo "-------结束--------"
exit
else
echo "该项目路径不存在"
echo "End"
exit
fi
更换 分支 代码目录 和 git仓库地址
如果出现权限问题 fatal: detected dubious ownership in repository at '/www/wwwroot/dingsun'
To add an exception for this directory, call:
可以通过 Git 配置添加异常,让 Git 忽略该目录的权限警告
git config --global --add safe.directory /www/wwwroot/dingsun
6 码云 git webhook 宝塔地址/hook?access_key=密钥¶m=1253
