shell 实现SVN自动下载、TAG分支版本、MAVEN编译打包

如题,多的话不说,直接上源码

1、SVN实现分支版本(copy)

if [ -z "${LOADED}" ]; then
    source ./env.conf
fi

if [ -z "${TO_VERSION}" ]; then
    echo "Usage:tag_all [-v svn_version -p project_name] to_version"
    exit 1
fi

MAVENPRO="cportal${TO_VERSION}"

if [ ! "${PROJECT_NAME}" == "" ]; then
    CPORTAL_TAG_PARENT_PATH="${PATH}/tags/cportal1.0.0/${MAVENPRO}"
    CPORTAL_TAG_PATH="${CPORTAL_TAG_PARENT_PATH}/${PROJECT_NAME}"
    CPORTAL_TRUNK_PATH="${PATH}/trunk/portal1.0.0/IECfmall/mavenPro/${PROJECT_NAME}"
    EXIST_TAG_PARENT_PATH=$(svn list ${CPORTAL_TAG_PARENT_PATH}|grep ${PROJECT_NAME})
else
    CPORTAL_TAG_PARENT_PATH="${PATH}/tags/cportal1.0.0"
    CPORTAL_TAG_PATH="${CPORTAL_TAG_PARENT_PATH}/${MAVENPRO}"
    CPORTAL_TRUNK_PATH="${PATH}/trunk/portal1.0.0/IECfmall/mavenPro"
    EXIST_TAG_PARENT_PATH=$(svn list ${CPORTAL_TAG_PARENT_PATH}|grep ${MAVENPRO})
fi

if [ -n "$EXIST_TAG_PARENT_PATH" ]; then
    echo "${CPORTAL_TAG_PATH} already exists"
    exit 1
fi


if [ -z "$SVN_VERSION" ]; then
    echo "svn --username=username cp ${CPORTAL_TRUNK_PATH} ${CPORTAL_TAG_PATH}"
    svn --username=username cp ${CPORTAL_TRUNK_PATH} ${CPORTAL_TAG_PATH} -m "commit log"
else
    echo "svn --username=username cp -r ${SVN_VERSION} ${CPORTAL_TRUNK_PATH} ${CPORTAL_TAG_PATH}"
    svn --username=username cp -r ${SVN_VERSION} ${CPORTAL_TRUNK_PATH} ${CPORTAL_TAG_PATH} -m "commit log"
fi

 

2、SVN从TAG版本下载(checkout)

if [ -z "${LOADED}" ]; then
    source ./env.conf
fi

if [ -z ${TO_VERSION} ]; then
    echo "Usage:checkout_all [-p project_name] to_version"
    exit 1
fi

if [ ! -d "$SRC_HOME" ]; then
    echo "==============create $SRC_HOME"
    mkdir -p $SRC_HOME
fi

cd $SRC_HOME

#删除除最近3个版本的以前版本
ls -rt|head -n -3|xargs -i rm -rf {}
check_success

MAVENPRO="cportal${TO_VERSION}"

if [ ! "${PROJECT_NAME}" == "" ]; then
    if [ ! -d "${SRC_HOME}/${MAVENPRO}" ]; then
        echo "==============create ${SRC_HOME}/${MAVENPRO}"
        mkdir -p ${SRC_HOME}/${MAVENPRO}
    fi
    cd "${SRC_HOME}/${MAVENPRO}"
    rm -rf ${PROJECT_NAME}
    CPORTAL_PATH="https://${PATH}/tags/cportal1.0.0/${MAVENPRO}/${PROJECT_NAME}"
    echo "svn checkout $CPORTAL_PATH"
    svn --username=username checkout $CPORTAL_PATH     
else
    cd $SRC_HOME
    rm -rf $MAVENPRO
    CPORTAL_PATH="https://${PATH}/tags/cportal1.0.0/${MAVENPRO}"
    echo "svn checkout $CPORTAL_PATH"
    svn --username=username checkout $CPORTAL_PATH $MAVENPRO    
fi

 

3、MAVEN编译及打包

if [ -z "${LOADED}" ]; then
    source ./env.conf
fi

if [ -z "${TO_VERSION}" ]; then
    echo "please input impl_all version"
    exit 1
fi

echo "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ALL impl execute start!!"
echo ""

#删除除最近3个版本的以前版本
cd ${DEPLOY_HOME}
ls -rt|head -n -3|xargs -i rm -rf {}
check_success

if [ -z "${PROJECT_NAME}" ]; then
    cd ${SRC_HOME}/cportal${TO_VERSION}/cportalaggregator
else
    cd ${SRC_HOME}/cportal${TO_VERSION}/${PROJECT_NAME}    
fi

mvn clean versions:set -DnewVersion=${TO_VERSION}
mvn -U  -Dmaven.test.skip=true -Dmaven.test.failture.ignore=true install
if [ $? -ne 0 ]; then
    exit 1
fi    

echo ""

DES_PATH="${DEPLOY_HOME}/cportal${TO_VERSION}/"
if [ ! -d "$DES_PATH" ]; then
    mkdir -p $DES_PATH
fi

if [ "${PROJECT_NAME}" == "" ]; then
    cd ${SRC_HOME}/cportal${TO_VERSION}
    for pathname in cportal*
    do
        if [ "${pathname}" == "cportalaggregator" ]; then
            continue
        fi
        
        FILE_LIST=$(ls -l ${SRC_HOME}/cportal${TO_VERSION}/${pathname}/target/|grep ^-|awk {print $9})
        for file_name in ${FILE_LIST}
        do
            echo "cp ${SRC_HOME}/cportal${TO_VERSION}/${pathname}/target/${file_name} $DES_PATH"
            cp -rf ${SRC_HOME}/cportal${TO_VERSION}/${pathname}/target/${file_name} $DES_PATH
        done
    done
else
    FILE_LIST=$(ls -l ${SRC_HOME}/cportal${TO_VERSION}/${PROJECT_NAME}/target/|grep ^-|awk {print $9})
    for file_name in ${FILE_LIST}
    do
        echo "cp -rf ${SRC_HOME}/cportal${TO_VERSION}/${PROJECT_NAME}/target/${PROJECT_NAME}-* ${DES_PATH}"
        cp -rf ${SRC_HOME}/cportal${TO_VERSION}/${PROJECT_NAME}/target/${PROJECT_NAME}-* ${DES_PATH}
    done
fi


echo ""
echo "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ALL impl execute end!!"

 

上述代码基础文件(env.conf):

if [ -z "${LOADED}" ]; then
    LOADED=1
fi

HOME=/home/mh
DEPLOY_HOME=$HOME/cportal1.0.0
LOG_HOME=$HOME/logs
SRC_HOME=$HOME/src

ARG_NUMBER=$#
while [ ${ARG_NUMBER} -gt 0 ]; 
do
    case $1 in
    (-v)
        shift
        SVN_VERSION=$1
        ;;
    (-p)
        shift
        PROJECT_NAME=$1
        ;;                
    (*)
        TO_VERSION=$1
        break;
        ;;
    esac
    shift
done

#判断是否成功
check_success(){
    if [ $? -ne 0 ]; then
        exit 1
    fi
}

mvn_cmd(){
    mvn -U  -Dmaven.test.skip=true -Dmaven.test.failture.ignore=true
}

echo_info(){
    echo "===================================================================================[$PROJECT_HOME/$1] execute end!!"
}

echo_interf_info(){
    echo "[PROJECT LIST]"
    cd $PROJECT_HOME
    ls -ld VCPCOMMON && ls -ld *I
    echo ""
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。