shell脚本git批量拉取代码

2019-06-10  本文已影响0人  hao0_0

前言:此代码只可做参照,因每个项目不同,拉取代码的方式不同

此项目有多个服务(微服务架构):pay-parent-pom pay-soa-base pay-spi 等.....。因此更新每个服务需要将服务git pull,很费时间,所以写了此shell脚本,一键更新所有的服务至最新。

思想:遍历所有的dirs服务列表,一个个命令更新执行。

代码如下1:

dirs=(pay-parent-pom pay-soa-base pay-spi pay-soa-spi pay-soa-framework soa-proxy-client pay-soa-gateway pay-soa-channel pay-soa-wallet basic-soa-pay pay-notify-web pay-notify-router pay-soa-risk pay-job pay-cron-job pay-risk-job pay-kms-spi pay-kms-client pay-soa-card)

for i in "${dirs[@]}";

do

    #mkdir $i

    #cd $i

    echo Pull `pwd start build..........................`...

    git clone http://gitlab.hq.com/pay/$i.git

    #git checkout master

    git pull -v

    #cd ..

done

代码如下2:(高级)

#!/usr/bin/expect

set timeout 10

set host "1.1.41.109"

set username "jiangjiahao"

set password "password "

dirs=(pay-parent-pom pay-soa-base pay-spi pay-soa-spi pay-soa-framework soa-proxy-client pay-soa-gateway pay-soa-channel pay-soa-wallet basic-soa-pay pay-notify-web pay-notify-router pay-soa-risk pay-job pay-cron-job pay-risk-job pay-kms-spi pay-kms-client pay-soa-card)

for i in "${dirs[@]}";

do

mkdir $i

    cd $i

    echo Pull `pwd start build..........................`...

    git checkout master

    expect "Username for 'http://gitlab.h.com'" {send "$username\r"}

    expect "Password for 'https://jiangjiahao@gitlab.hqygou.com'" {send "$password\r"}

    interact

    git pull -v

    cd ..

done

上一篇下一篇

猜你喜欢

热点阅读