作者:Eddy 历史版本:1 最后编辑:Eddy 更新时间:2024-11-15 09:05
新建jenkins任务
新增任务
配置svn源码路径、账号
配置构建环境
配置构建
脚本内容:
cd $WORKSPACE/build; # 切换到工具目录 sh jenkins.8081.deploy.sh; # 构建程序 error_count=`grep "ERROR" ant.8081.log | wc -l`; if [ ${error_count} -eq 0 ]; then OLD_BUILD_ID=$BUILD_ID; echo $OLD_BUILD_ID; export BUILD_ID=dontKillMe; echo "sh /opt/jenkins/scp.220.staging.sh" | at now+1min; # 自动部署程序 export BUILD_ID=$OLD_BUILD_ID; echo $BUILD_ID; else echo "Package has Error." set -e #注意,这句最重要,一定要先设置这个,非常感谢 诺亚舟 的提示 exit 1 #然后再退出,jenkins就会报红显示构建失败 fi
- jenkins打包工具相关配置详见: 工具配置
scp.220.staging.sh
文件内容:#!/bin/bash j_home=/var/lib/jenkins/workspace/ibps3-staging s_home=/opt/jenkins/ibps3-staging ssh 192.168.3.220 rm -rf ${s_home}/ibps-basis-zuul-exclude ${s_home}/ibps-oauth-server2-exclude ${s_home}/ibps-provider-platform-exclude ${s_home}/ibps-provider-business-exclude; scp -r ${j_home}/3-ibps3-v3.1-dev/ibps-basis-root/modules/basis-zuul/target/ibps-basis-zuul-exclude root@192.168.3.220:${s_home}/; scp -r ${j_home}/3-ibps3-v3.1-dev/ibps-oauth-root/modules/oauth-server2/target/ibps-oauth-server2-exclude root@192.168.3.220:${s_home}/; scp -r ${j_home}/3-ibps3-v3.1-dev/ibps-provider-root/modules/provider-platform/target/ibps-provider-platform-exclude root@192.168.3.220:${s_home}/; scp -r ${j_home}/3-ibps3-v3.1-dev/ibps-provider-root/modules/provider-business/target/ibps-provider-business-exclude root@192.168.3.220:${s_home}/; ssh -f -n 192.168.3.220 sh ${s_home}/reset.sh e;
- 主机间设置了免密登陆操作,相关设置可自行百度。
192.168.3.220机器上的
reset.sh
文件内容:#!/bin/bash script_home=$(cd `dirname $0`; pwd) ibps_home=/home/v3/ibps-staging-v3 # 真实的部署目录 script_username=v3 # 真的的部署用户名 # stop all services. echo "stop all service." su ${script_username} -l -c "sh ${ibps_home}/stop.sh;" #echo "sleeping 3s." #sleep 3; # remove all old service files. echo "remove all old service files." rm -rf ${ibps_home}/zuul-test ${ibps_home}/oauth2server-test ${ibps_home}/platform-test ${ibps_home}/business-test; #echo "sleeping 3s." #sleep 3; # copy all new service files. echo "copy all new service files." cp -rf ${script_home}/ibps-basis-zuul-exclude ${ibps_home}/zuul-test; cp -rf ${script_home}/ibps-oauth-server2-exclude ${ibps_home}/oauth2server-test; cp -rf ${script_home}/ibps-provider-platform-exclude ${ibps_home}/platform-test; cp -rf ${script_home}/ibps-provider-business-exclude ${ibps_home}/business-test; #echo "sleeping 3s." #sleep 3; # chown all new service fles. echo "chown all new service fles." chown -R ${script_username}:${script_username} ${ibps_home}/zuul-test; chown -R ${script_username}:${script_username} ${ibps_home}/oauth2server-test; chown -R ${script_username}:${script_username} ${ibps_home}/platform-test; chown -R ${script_username}:${script_username} ${ibps_home}/business-test; #echo "sleeping 3s." #sleep 3; # start all services. echo "start all services. " su ${script_username} -l -c "cd ${ibps_home};sh start.sh;" if [ -n "$1" ] ;then echo "exit..."; exit; fi
配置构建任务
立即构建: