购物免费领券就上搜券网,搜券网Souquan.Net带你来省钱,搜券领券再买,更省钱,半价抢先购!

很简单的git自动化部署脚本

Git 扩产网 915℃ 0评论

最近在用thinkPHP写一个App的接口,因为测试发布频繁,就写了一个简单的发布脚本。

#!/bin/bash

# Before run this script, make sure test is ok.

GITDIR=/home/wwwroot/deploy #发布目录
PROGRAMDIR=/home/wwwroot/www.kuochan.com #项目目录
srcGitUrl=”git@gitee.com:kuochan/kuochan.git” #修改为自己的git地址

publish(){
local branch=$1
echo “=== start clone code ===”
[ ! -d $GITDIR ] && echo “$GITDIR not found” && exit 1
if [ -d $GITDIR/.git ]
then
cd $GITDIR
git pull || exit 1
git checkout $branch || exit 1
else
git clone -b $branch $srcGitUrl $GITDIR || exit 1
fi
rsync -auq –exclude $GITDIR/.git $PROGRAMDIR #仅从发布目录同步修改的文件到项目目录,并忽略掉.git目录
echo “=== publish ok, confirm ===”
}

print_help(){
echo “$0 [options]”
printf “\t–test; update code from git to test\n”
printf “\t–help,-h; print this message\n”
}

[ $# -ne 1 ] && print_help && exit 1

case $1 in
*) publish $1;;
esac

使用方法:bash publish.sh master,发布master分之代码,并同步到项目目录。

 

转载请注明:扩产网 » 很简单的git自动化部署脚本

喜欢 (2)
发表我的评论
取消评论
表情

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

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