通过GIT_COMMIT进行代码回滚

首先需要安装插件:conditional-buildstep

A buildstep wrapping any number of other buildsteps, controlling their execution based on a defined condition (e.g. BuildParameter).
 
 
1、构建代码时,需要记录每次构建的GIT_COMMIT,保存到一个文本中,以构建编号进行命名:
#!/bin/sh

#$1:send branch
#$2:jenkins build id
#$3:git commit

branch=$1
version=$2
commit=$3

case $branch in
    Pre)
        echo "branch: ${branch}"
        echo "version: ${version}"       
        echo "commit: ${commit}"       
        #同步代码到发布目录  
        #to do
        
        
        #备份版本git commit
        echo ${commit}>/home/wos/test2/${version}.txt

        ;;
    Real)
        echo "branch: ${branch}"
        echo "version: ${version}"       
        echo "commit: ${commit}"     
        #同步代码到发布目录
        #to do
        
        
        #备份版本git commit
        echo ${commit}>/home/wos/test2/${version}.txt

        ;;
    Rollback_Pre)
        echo "branch: ${branch}"
        echo "version: ${version}"       
        echo "commit: ${commit}"     
        #同步代码到发布目录 
        #to do
        ;;
    Rollback_Real)
        echo "branch: ${branch}"
        echo "version: ${version}"       
        echo "commit: ${commit}"     
        #同步代码到发布目录 
        #to do
        ;;
    *)
        exit
        ;;
esac

 

2、进行回滚

case $deploy_evn in
    Rollback_Pre)
        url="$pre_version"
        ;;
    Rollback_Real)
        url="$real_version"
        ;;
    *)
        exit
        ;;
esac

model="$deploy_evn"
projectName=`echo "$url"|awk -F '/' '{print $6}'`
rollbackID=`echo "$url"|awk -F '/' '{print $7}'`


#获取回滚GIT_COMMIT
commit=$(cat /home/wos/test2/${rollbackID}.txt)
#进入备份目录
cd /home/wos/test3/WOS_Portal/
#下载最新代码
git clone http://username:password@git.wondershare.cn/CPStudio/WOS_Portal.git
#本地回滚代码
git reset --hard ${commit}
#回滚代码到WEB服务器
/bin/sh /usr/local/rsync/portal/portal.sh $model $rollbackID

 

 

 

 

转载于:https://www.cnblogs.com/ai594ai/p/9225112.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值