git 自動上傳程式碼到遠端倉庫

abin1703發表於2021-04-02
自動上傳應用程式碼到git倉庫中。具體詳見程式碼。
if [[ $1 = "--help" ]] || [[ $1 = "-h" ]]
then
echo "1、專案名稱請選擇以下定義好的名稱"
echo  "
社保專案 :newsx、sxzw、reporting、reportingSYN、
微服務vspn30 :eapi 、fxkz、jdjc、screen、zwgl、service
"
echo "2、升級環境請選擇以下定義好的名稱"
echo "
生產環境 : prod
開發環境 : dev
"
echo "3、升級包位置請輸入上傳升級包存放的位置"
echo "
示例 : /z/02升級補丁包/01newsx/20210401/newsx
"
exit 0
fi
read -p "請輸入專案名稱:" project
read -rp "請輸入升級包位置:" sjpath_bat
read -p "請輸入升級環境:" sjenv
echo "----------------------------------"
echo -e "\033[0;31;1m輸入的專案名稱為:${project}\033[0m"
echo -e "\033[0;31;1m輸入的升級包位置為: ${sjpath_bat}\033[0m"
echo -e "\033[0;31;1m輸入的升級環境為:${sjenv}\033[0m"
echo "----------------------------------"
riqi=`date +'%Y%m%d'`
riqitime=`date +'%Y%m%d_%H%M%S'`
sjpath=$(echo $sjpath_bat |sed -e 's/\\/\//g'|sed -e 's/z:/\/z/')
echo $sjpath
if [ $sjenv == 'dev' ];then
cd /z/01業務升級/dev/
if [ $project == 'newsx' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd newsx
git checkout -B "dev_newsx_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_newsx_$riqitime"
git push --set-upstream origin "dev_newsx_$riqi"
echo -e "\033[45m 分支名稱為:dev_newsx_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_newsx_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'sxzw' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd sxzw
git checkout -B "dev_sxzw_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_sxzw_$riqitime"
git push --set-upstream origin "dev_sxzw_$riqi"
echo -e "\033[45m 分支名稱為:dev_sxzw_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_sxzw_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'reporting' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd reporting
git checkout -B "dev_reporting_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_reporting_$riqitime"
git push --set-upstream origin "dev_reporting_$riqi"
echo -e "\033[45m 分支名稱為:dev_reporting_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_reporting_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'reportingSYN' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd reportingSYN
git checkout -B "dev_reportingSYN_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_reportingSYN_$riqitime"
git push --set-upstream origin "dev_reportingSYN_$riqi"
echo -e "\033[45m 分支名稱為:dev_reportingSYN_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_reportingSYN_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'eapi' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-eapi
git checkout -B "dev_eapi_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_eapi_$riqitime"
git push --set-upstream origin "dev_eapi_$riqi"
echo -e "\033[45m 分支名稱為:dev_eapi_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_eapi_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'fxkz' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-fxkz
git checkout -B "dev_fxkz_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_fxkz_$riqitime"
git push --set-upstream origin "dev_fxkz_$riqi"
echo -e "\033[45m 分支名稱為:dev_fxkz_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_fxkz_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'jdjc' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-jdjc
git checkout -B "dev_jdjc_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_jdjc_$riqitime"
git push --set-upstream origin "dev_jdjc_$riqi"
echo -e "\033[45m 分支名稱為:dev_jdjc_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_jdjc_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'screen' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-screen
git checkout -B "dev_screen_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_screen_$riqitime"
git push --set-upstream origin "dev_screen_$riqi"
echo -e "\033[45m 分支名稱為:dev_screen_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_screen_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'zwgl' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-zwgl
git checkout -B "dev_zwgl_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_zwgl_$riqitime"
git push --set-upstream origin "dev_zwgl_$riqi"
echo -e "\033[45m 分支名稱為:dev_zwgl_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_zwgl_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'service' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vst-service
git checkout -B "dev_service_$riqi"
cp -rf $sjpath /z/01業務升級/dev
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: dev_service_$riqitime"
git push --set-upstream origin "dev_service_$riqi"
echo -e "\033[45m 分支名稱為:dev_service_$riqi \033[0m"
echo -e "\033[45m Commit ID:dev_service_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
else
    echo "輸入的專案名稱不存在,請執行 sh git.sh --help 檢視具體專案名稱!!"
fi
elif [ $sjenv == 'prod' ];then
cd /z/01業務升級/product/
if [ $project == 'newsx' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd newsx
git checkout -B "prod_newsx_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_newsx_$riqitime"
git push --set-upstream origin "prod_newsx_$riqi"
echo -e "\033[45m 分支名稱為:prod_newsx_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_newsx_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'sxzw' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd sxzw
git checkout -B "prod_sxzw_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_sxzw_$riqitime"
git push --set-upstream origin "prod_sxzw_$riqi"
echo -e "\033[45m 分支名稱為:prod_sxzw_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_sxzw_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'reporting' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd reporting
git checkout -B "prod_reporting_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_reporting_$riqitime"
git push --set-upstream origin "prod_reporting_$riqi"
echo -e "\033[45m 分支名稱為:prod_reporting_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_reporting_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'reportingSYN' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd reportingSYN
git checkout -B "prod_reportingSYN_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_reportingSYN_$riqitime"
git push --set-upstream origin "prod_reportingSYN_$riqi"
echo -e "\033[45m 分支名稱為:prod_reportingSYN_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_reportingSYN_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'eapi' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-eapi
git checkout -B "prod_eapi_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_eapi_$riqitime"
git push --set-upstream origin "prod_eapi_$riqi"
echo -e "\033[45m 分支名稱為:prod_eapi_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_eapi_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'fxkz' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-fxkz
git checkout -B "prod_fxkz_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_fxkz_$riqitime"
git push --set-upstream origin "prod_fxkz_$riqi"
echo -e "\033[45m 分支名稱為:prod_fxkz_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_fxkz_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'jdjc' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-jdjc
git checkout -B "prod_jdjc_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_jdjc_$riqitime"
git push --set-upstream origin "prod_jdjc_$riqi"
echo -e "\033[45m 分支名稱為:prod_jdjc_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_jdjc_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'screen' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-screen
git checkout -B "prod_screen_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_screen_$riqitime"
git push --set-upstream origin "prod_screen_$riqi"
echo -e "\033[45m 分支名稱為:prod_screen_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_screen_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'zwgl' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vspn30-zwgl
git checkout -B "prod_zwgl_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_zwgl_$riqitime"
git push --set-upstream origin "prod_zwgl_$riqi"
echo -e "\033[45m 分支名稱為:prod_zwgl_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_zwgl_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
elif [ $project == 'service' ];then
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
cd vst-service
git checkout -B "prod_service_$riqi"
cp -rf $sjpath /z/01業務升級/product
if [ $? == 0 ];then
echo -e "\033[42m升級檔案複製成功!!!\033[0m"
else
echo -e "\033[41m升級檔案複製失敗!!!\033[0m"
exit 1
fi
git add .
git commit -m "Push Code: prod_service_$riqitime"
git push --set-upstream origin "prod_service_$riqi"
echo -e "\033[45m 分支名稱為:prod_service_$riqi \033[0m"
echo -e "\033[45m Commit ID:prod_service_$riqitime \033[0m"  
echo -e "\033[42m 上傳升級完到gitlab成功!!\033[0m"
else
echo "輸入的專案名稱不存在,請執行 sh git.sh --help 檢視具體專案名稱!!"
fi
else
echo "輸入升級環境不存在,請選擇生產環境(prod) 或者 開發環境(dev)"
fi


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2766382/,如需轉載,請註明出處,否則將追究法律責任。

相關文章