git-自动化脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git-自动化脚本相关的知识,希望对你有一定的参考价值。
首先我们要从https://github.com/github 上申请一个GitHub仓库。(过程就不介绍了)
现在我们来写个git的自动回滚脚本-通过版本号来回滚代码。
cat /usr/local/src/git.sh
#!/bin/bash
#author:xiaozhagn
mail_user="[email protected]"
WORK_DIR=/learngit/
REPLOY="zrh"
SRC_DIR=/data #已存在
IP=172.25.0.31
[email protected]:xiaozhagn/zrh.git
send_mail () {
echo "$1" | mail -s "Gits current version" $mail_user
}
git_pull(){
if [ ! -d $WORK_DIR ];then
mkdir $WORK_DIR
fi
}
git_add_tag(){
git_pull
tag_num=$(($(git tag | wc -l)+1))
tag_deploy="v$tag_num.0"
git tag -a $tag_deploy -m "$tag_deploy"
git push -f
git push --tag
}
git_deploy(){
rsync -vzrtopg --progress $WORK_DIR/$REPLOY/* $IP:$SRC_DIR
cd $WORK_DIR/$REPLOY
tag_status=$(git tag | tail -n 1)
echo "$tag_status"
send_mail $tag_status
ssh 172.25.0.31 ln -s $SRC_DIR /web/
}
git_reset(){
PS3="Select a number: "
cd $WORK_DIR/$REPLOY
while true ; do
read -p "Does reset your version yes/no": input
if [ $input == yes ]; then
select rollback in "quick rollback" "rollback you need version"; do
case $rollback in
"quick rollback")
git reset --hard HEAD^
git push -f
tag1_status=$(git tag | tail -n 1)
send_mail $tag1_status
echo $tag1_status
quit
;;
"rollback you need version" )
list_version=$(git tag)
select version in $list_version ; do
gti reset --hart $version
git push -f
tag2_status=$(git tag | tail -n 1)
send_mail $tag2_status
echo $tag2_status
break
done ;;
esac
done
else
if [ $input == no ]; then
exit
fi
if [ $input == * ] ; then
echo "Please yes or on"
fi
fi
done
}
line(){
echo "Please echo \"main\""
echo "If you check your script file please input \"git_add_tag/git_deploy/git_reset again\" "
}
line
main(){
git_add_tag
git_deploy
git_reset
}
$1
本文出自 “我的运维” 博客,谢绝转载!
以上是关于git-自动化脚本的主要内容,如果未能解决你的问题,请参考以下文章