• Welcome to LiuJason's Blog!

使用Webhook+Git实现代码自动部署

Linux笔记 Jason 4 years ago (2019-11-22) 930 Views 0 Comments QR code of this page
#!/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="[email protected]:cloudraft/$1.git"

echo "Web站点路径:$gitPath"

#判断项目路径是否存在
if [ -d "$gitPath" ]; then
        cd $gitPath
        #判断是否存在git目录
        if [ ! -d ".git" ]; then
                echo "在该目录下克隆 git"
                sudo -u www git clone $gitHttp gittemp
                mv gittemp/.git .
                rm -rf gittemp
        fi
        #拉取最新的项目文件

		sudo git reset --hard origin/master
        sudo git pull
		sudo -u git rev-parse HEAD
        #设置目录权限
        chown -R www:www $gitPath
        echo "End"
        exit
else
        echo "该项目路径不存在"
        echo "End"
        exit
fi

This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/393.html
Like (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址