#!/bin/bash refs=$1 echo ${refs} project=shf-jy project_dir=/data/repos/${project} project_url=https://gz-gitlab.vipthink.cn/sh-jy/shf-jy.git token=d926aee0ab9d2663d03ec8698327c8f131cbc7c43f804f7f635e5db9884c27a1 cd ${project_dir} # 通知 DingSuccess () { curl 'https://oapi.dingtalk.com/robot/send?access_token='"${token}"'' \ -H 'Content-Type: application/json' -d '{"msgtype": "text", "text": { "content": "'" 项目名称:${project} 构建分支/tag:${branch_tag}"' 状态:构建成功" }}' } DingError () { curl 'https://oapi.dingtalk.com/robot/send?access_token='"${token}"'' \ -H 'Content-Type: application/json' -d '{"msgtype": "text", "text": { "content": "'"${branch_tag}\n${project}"' 构建过程中有错误" } }' } CheckStatus () { if [ $? -eq 0 ];then DingSuccess else DingError fi } CheckBuild () { if [ $? -ne 0 ];then DingError exit 1 fi } ############## dev ############################################################## if [[ "${refs}" == refs/heads/dev-* ]];then branch_tag=`echo ${refs}|awk -F '/' '{print $NF}'` [ -d ${project} ] && rm -rf ${project} if [ ! -d ${branch_tag} ];then echo echo "开始拉取代码......." git clone ${project_url} mv ${project} ${branch_tag} cd ${branch_tag} else cd ${branch_tag} fi git reset --hard git pull git checkout ${branch_tag} git pull cnpm i npm run build CheckBuild echo ${branch_tag} >./dist/version.log rsync -avz -e 'ssh -p 22' ./dist/ shop@106.54.66.104:/data/wwwroot/shd-jy.vipthink.cn/static/ CheckStatus ############## dev ############################################################## elif [[ "${refs}" == refs/heads/shd-* ]];then branch_tag=`echo ${refs}|awk -F '/' '{print $NF}'` [ -d ${project} ] && rm -rf ${project} if [ ! -d ${branch_tag} ];then echo echo "开始拉取代码......." git clone ${project_url} mv ${project} ${branch_tag} cd ${branch_tag} else cd ${branch_tag} fi git reset --hard git pull git checkout ${branch_tag} git pull cnpm i npm run build echo ${branch_tag} >./dist/version.log rsync -avz -e 'ssh -p 22' ./dist/ shop@106.54.66.104:/data/wwwroot/shd-jy.vipthink.cn/admin_vipthink/public/dist/ CheckStatus ############ test ############################ elif [[ "${refs}" == refs/tags/sht-* ]];then branch_tag=`echo ${refs}|awk -F '/' '{print $NF}'` [ -d ${project} ] && rm -rf ${project} echo echo "开始拉取代码......." git clone ${project_url} if [ ! -d ${branch_tag} ];then mv ${project} ${branch_tag} cd ${branch_tag} else echo "${branch_tag}已经发布......." rm -rf ${project} exit 0 fi git pull git checkout ${branch_tag} git pull cnpm i npm run build echo ${branch_tag} >./dist/version.log rsync -avz --delete -e 'ssh -p 22' ./dist/ shop@49.234.220.191:/data/wwwroot/sht-jy.vipthink.cn/static/ rsync -avz --delete -e 'ssh -p 22' ./dist/ shop@sht:/data/wwwroot/sht-jy.vipthink.cn/static/ CheckStatus ########## pre ############### elif [[ "${refs}" == refs/tags/shp-* ]];then branch_tag=`echo ${refs}|awk -F '/' '{print $NF}'` [ -d ${project} ] && rm -rf ${project} echo echo "开始拉取代码......." git clone ${project_url} if [ ! -d ${branch_tag} ];then mv ${project} ${branch_tag} cd ${branch_tag} git checkout ${branch_tag} git pull else echo "${branch_tag}已经发布......." rm -rf ${project} exit 0 fi git pull git checkout ${branch_tag} git pull cnpm i npm run build echo ${branch_tag} >./dist/version.log rsync -avz -e 'ssh -p 22' ./dist/ shop@10.104.10.92:/data/wwwroot/shp-jy.vipthink.cn/static/ CheckStatus ############# sho ################ elif [[ "${refs}" == refs/tags/sho-* ]];then branch_tag=`echo ${refs}|awk -F '/' '{print $NF}'` [ -d ${project} ] && rm -rf ${project} echo echo "开始拉取代码......." git clone ${project_url} if [ ! -d ${branch_tag} ];then mv ${project} ${branch_tag} cd ${branch_tag} git checkout ${branch_tag} git pull else echo "${branch_tag}已经发布......." rm -rf ${project} exit 0 fi git pull git checkout ${branch_tag} git pull cnpm i npm run build echo ${branch_tag} >./dist/version.log rsync -avz -e 'ssh -p 22' ./dist/ shop@10.104.142.2:/data/wwwroot/sho-jy.vipthink.cn/admin_vipthink/public/dist/ CheckStatus else echo Ignore the build fi