平常构建项目中会用到的一些脚本

在jenkins 构建服务前校验分支是否合并了master 

#!/bin/bash
echo ${branches}

if [[ ${branches} != hotfix* && ${branches} != release* && ${branches} != feature* && ${branches} != master* ]];then

echo -e '\033[31m 分支格式不对,请获取hotfix 或者release分支 或者 feature分支 \033[0m'
exit 1

fi

echo '切换到master主干'

git checkout master

echo '获取master的最新代码'

git pull origin master

echo '获取master的最新commitid'

commid=`git rev-parse HEAD`

echo $commid

echo '获取上线分支是否包含master的最新commitid'

result=`git branch -a --contains ${commid}`


if [[ $result =~ ${branches} ]];then
echo '可以打包上线'
git checkout ${branches}
git pull origin ${branches}

else
echo -e '\033[31m 你又没合并master ,请自行检查合并 \033[0m'
exit 1

echo $result

fi

*********************************8

上线结束后,自动进行代码合并

if [[ ${branches} == master ]];then
echo '代码合并失败,请使用非master分支'
exit 0
fi

if [[ ${branches} != hotfix* && ${branches} != release* ]];then

echo -e '\033[31m 分支格式不对,请获取hotfix 或者release分支,不进行合并 \033[0m'
exit 1

fi

echo '切换到master主干'

git checkout master

echo '获取master的最新代码'

git pull origin master

echo '获取master的最新commitid'

commid=`git rev-parse HEAD`

echo $commid

echo '获取上线分支是否包含master的最新commitid'

result=`git branch -a --contains ${commid}|grep ${branches}`
echo $result
if [ $result != "" ];then
echo '开始执行合并代码到master, develop'
git checkout ${branches}
git pull origin ${branches}
git checkout master
git pull origin master
git merge ${branches}
git push origin master
git checkout develop
git pull origin develop
git merge ${branches}
git push origin develop
else
echo -e '\033[31m 上线包不包含master分支,上线包有问题 \033[0m'
exit 1echo $result

************************************

 

posted on   yingchen  阅读(207)  评论(0编辑  收藏  举报

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示