【Git】自动化Maven项目构建脚本(一)

在公司服务器上搭了个自动化构建环境,一上午写了个构建脚本,现在贴出来给自己看

#!/bin/bash

# .配置路径变量
    propath=/home/hotspot/.autoBuild/project
    war_box=/home/hotspot/.autoBuild/project/war_box

# .war包的最终整理的路径
    if [ -d $war_box ] ; then
        find $war_box -name '*.war' -type f -exec rm {} \;
    else
        mkdir -p $war_box
    fi

# .项目分支名称
    #cas_branch=multi_tenant_removed
    #portal_branch=new_portal
    #platform_branch=dev-

# .判断配置文件是否存在,存在则执行配置文件
    if [ -f "$1" ] ; then

        source $
    else
        echo "Configuration File Not Found!"
        exit
    fi

# .自动化构建 security 项目
    cd $propath
    # 不存在项目,则执行克隆
    [ -d platform ] || git clone ssh://git@www.xank.com.cn:10022/base_framework/platform.git
    cd platform
    # 获得当前项目分支名称
    currentBranch=`git branch | grep ^\* | sed -r "s/\*\s//g"`
    # 如果分支名称不一致则检出
    [ "$platform_branch"="$currentBranch" ] || git checkout -b $platform_branch remotes/origin/$platform_branch
    # 拉取最新代码
    git pull
    cd security-base
    # 编译并安装到本地仓库
    mvn clean install
    cd ../security
    # 编译打包指定概要文件
    mvn clean package -Pdeploy
    # 移动生成的war包到指定目录
    mv target/security.war $war_box

############## 与第5步一样,可不看 ###################
# .自动化构建 portal 项目
    cd $propath
    [ -d portal ] || git clone ssh://git@www.xank.com.cn:10022/base_framework/portal.git
    cd portal
    currentBranch=`git branch | grep ^\* | sed -r "s/\*\s//g"`
    [ "$portal_branch"="$currentBranch" ] || git checkout -b $portal_branch remotes/origin/$portal_branch
    git pull
    mvn clean package -Pdeploy
    mv target/portal.war $war_box

############## 与第5步一样,可不看 ###################
# . 自动化构建 cas 项目
    cd $propath
    [ -d cas ] || git clone ssh://git@www.xank.com.cn:10022/base_framework/cas.git
    cd cas
    currentBranch=`git branch | grep ^\* | sed -r "s/\*\s//g"`
    [ "$cas_branch"="$currentBranch" ] ||  git checkout -b $cas_branch remotes/orgin/$cas_branch
    git pull
    mvn clean package -Pdeploy
    mv target/cas.war $war_box
上一篇:Library cache lock 故障解决一例


下一篇:Library Cache: Lock, Pin and Load Lock