jekins批量打包脚本


批量打包

sh build.sh master  就打master分支的包

cat build.sh 
# java -jar /data/luban/jenkins-cli.jar -s http://xxx.hupun.org:4180/ -auth 用户名:密码 build isc-base -s
function starJob(){
        job=$1
        branch=$2

        thisBuild=$(java -jar /data/cb2b/jenkins-cli.jar -s http://192.168.xx.xxx:4180/ -auth 用户名:密码 build $job -p branch=$branch -s)
        if [[ $thisBuild == *"SUCCESS"* ]]; then
                echo "$job build success!"
                return 1
        fi
        echo "$job build failed!"
        return 0
}


branch=$1
if [[ $branch == "" ]]; then
        branch="test"
fi
pack_jobs=("cb2b-backend" "cb2b-base" "cb2b-core" "cb2b-cronjob" "cb2b-mall" "cb2b-mobile" "cb2b-system")
start_jobs=("cb2b-starter-dev")
pids=()
echo "pack $branch"

buildtimes=0
buildSuccess=0

#编译各个工程的包
while [[ $buildSuccess != ${#pack_jobs[*]} ]]; do
        buildSuccess=0
        let buildtimes++

        echo "------ start build -------"

        for job in ${pack_jobs[@]}; do
                starJob $job $branch &
                pids[${#pids[*]}]=$!
        done

        for pid in ${pids[@]}; do
                wait $pid
                result=$?
                buildSuccess=$(($buildSuccess + $result))
        done
        pids=()
        echo "------ end build -------"

        if [[ buildtimes -gt 3 ]]; then
                echo "$(date "+%Y-%m-%d %H:%M:%S") build failed! buildtimes = $buildtimes"
                break
        fi
done

if [[ $buildSuccess -eq ${#pack_jobs[*]}  ]]; then
        #发布starter
        for job in ${start_jobs[@]}; do
                starJob $job $branch &
        done
        echo "$(date "+%Y-%m-%d %H:%M:%S") build success! buildtimes = $buildtimes"
fi
 

你可能感兴趣的:(java,开发语言)