公司目前尚未持續繼承工具,每次項目發佈都要手工操做,以爲總是在作重複工做,因此本身就寫了個shell腳原本自動發佈,相關工具包括:git、maven、maven assembly插件、ssh 、awk、xargsgit
#!/bin/bash # 本地項目根目錄 project_root='/Users/xx/project/xx-project/' # 發佈的maven模塊名 deploy_module='xx-module' # maven打包後的zip包名 package_name='xx.zip' # 服務器上的發佈路徑 server_deloy_path='/data/xx-server' # 解壓後包名 unpackage_name='xx-server' # 服務器IP server_ip='10.17.2.88' # 服務器端口 server_port=xx cd $project_root echo '開始更新代碼' git co xx_dev && git pull origin xx_dev echo '開始maven打包...' mvn clean package -P assembly-all -DskipTests=true echo '開始上傳包...' scp -P ${server_port} ${project_root}/${deploy_module}/target/${package_name} root@${server_ip}:${server_deloy_path} echo '開始刪除舊包...' command='cd '${server_deloy_path}' && rm -rf logs/ bin/ lib/ '${unpackage_name} ssh -p ${server_port} root@${server_ip} ${command} echo '開始解壓包...' command='unzip '${server_deloy_path}/${package_name}' -d '${server_deloy_path} ssh -p ${server_port} root@${server_ip} ${command} echo '開始複製解壓後目錄...' command='cd '${server_deloy_path}' && cp -rf '${server_deloy_path}/${unpackage_name}'/* . && rm -rf '${unpackage_name} ssh -p ${server_port} root@${server_ip} ${command} echo '開始中止以前服務...' command="jps -v | grep "${server_deloy_path}" |awk 'NR==1{print $1}'" ssh -p ${server_port} root@${server_ip} ${command} | awk '{print $1}'| xargs ssh -p ${server_port} root@${server_ip} ' kill ' echo '開始啓動服務...' command='cd '${server_deloy_path}' && ./bin/start.sh' ssh -p ${server_port} root@${server_ip} ${command} echo '開始顯示日誌...' ssh -p ${server_port} root@${server_ip} 'tail -f '${server_deloy_path}'/logs/xx.log'