目标:实现宝塔webhook对接 码云 自动 pull
一. 准备工作
码云申请账号,建立仓库
服务器安装宝塔,GIT和webhook
二.
1.服务器安装 GIT
1  | yum install git  | 
2.宝塔安装 webhook插件

3.添加脚本

注意:
其中 “$1”是参数,是你码云仓库的名称,脚本内容大致是:”收到通信后,去指定的地方拉取master的分支代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  | #!/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/$1" #git网址 码云仓库地址 gitHttp="https://gitee.com/yourname/$1.git" echo "Web站点路径:$gitPath" #判断项目路径是否存在 if [ -d "$gitPath" ]; then         cd $gitPath         #判断是否存在git目录         if [ ! -d ".git" ]; then                 echo "在该目录下克隆 git"                 sudo git clone $gitHttp gittemp                 sudo mv gittemp/.git .                 sudo rm -rf gittemp         fi         echo "拉取最新的项目文件"         #sudo git reset --hard origin/master         git reset --hard origin/master         sudo git pull                 echo "设置目录权限"         sudo chown -R www:www $gitPath         echo "End"         exit else         echo "该项目路径不存在"         echo "End"         exit fi  | 

发表评论 取消回复