#!/bin/bash
DATE=`date +%F-%H-%M-%S`
FORK=master
TAG=0
v=版本号
WPATH=/打包根路径

#build fork-1.2.0
if [ $# = 1 ]
then
  echo "打包分支:$1"
  FORK=$1
fi

#build tag 1.2.0.release
if [ $# = 2 ]
then
  echo "打包TAG:$2"
  FORK=$1
  TAG=$2
fi

mkdir -p $WPATH/wars
#delete maven cache
rm -rf /root/.m2/repository/项目包路径


cd $WPATH
#init git
if [ ! -d "$WPATH/代码根目录" ] || [ ! -f "$WPATH/代码根目录/pom.xml" ];
then
    echo "git clone XXX项目"
    git clone http://代码路径 >/dev/null 2>&1
fi

#打包项目
cd $WPATH/代码根目录
echo "mvn install XXX项目"
git fetch origin
#build branch
if [ $TAG = 0 ]
then
  git checkout -b $FORK origin/$FORK
  git checkout $FORK
  git pull origin $FORK >/dev/null 2>&1
fi
#build tag
if [ $TAG != 0 ]
then
  git tag -l | xargs git tag -d
  git fetch -t -p -f
  git checkout $TAG
fi
#git -c core.quotepath=false checkout commitID^0 --
mvn clean install -Dmaven.test.skip=true >$WPATH/pack.log

test=`grep "BUILD SUCCESS" $WPATH/pack.log`
if [ ! "$test" = "" ];
then
\cp target/*-$v.jar $WPATH/wars/
echo "mvn OK"
else
  echo "mvn Fail"
fi

发表评论

电子邮件地址不会被公开。 必填项已用*标注