图1、发布流程图,原理是编包和发布jenkins分开,每次发布的版本都存储在编译的机器上。
图2、编包jenkins的输入参数
图3、发布jenkins输入的参数
代码1、编包cp
代码语言:javascript复制config_file=/home/data/workspace-jenkins/deploy_msg_sender/cpp/src/msg_sender/conf
bin_file=/home/data/workspace-jenkins/deploy_msg_sender/cpp/src/msg_sender/msg_sender
msg_file=/home/data/workspace-jenkins/deploy_msg_sender_release
mkdir $msg_file/msg_sender_${compile_version}
cp -a $config_file $msg_file/msg_sender_${compile_version}/
cp $bin_file $msg_file/msg_sender_${compile_version}/
代码2、发布
代码语言:javascript复制config_file=/home/data/workspace-jenkins/deploy_msg_sender/cpp/src/msg_sender/conf
bin_file=/home/data/workspace-jenkins/deploy_msg_sender/cpp/src/msg_sender/msg_sender
msg_file=/home/data/workspace-jenkins/deploy_msg_sender_release
target_name=/opt/imserver/msg_sender
if test $environ == Test
then
target="10.0.0.181"
sed -i "s/server_host=.*/server_host=$target/g" $msg_file/msg_sender_$compile_version/conf/msg_sender.ini
if [ -f msg_sender_$compile_version.tar ]; then rm -rf msg_sender_$compile_version.tar; fi
tar -cvf msg_sender_$compile_version.tar msg_sender_$compile_version/
tar_name="/home/data/workspace-jenkins/deploy_msg_sender_release/msg_sender_$compile_version.tar"
command_1="cd $target_name && if [ -f msg_sender_$compile_version.tar ]; then rm -rf msg_sender_$compile_version.tar; fi"
command_2="cd $target_name && if [ -f msg_sender_$compile_version ]; then rm -rf msg_sender_$compile_version; fi"
command_3="cd $target_name && tar -xvf msg_sender_$compile_version.tar"
command_4="cd $target_name && ln -snf msg_sender_$compile_version msg_sender"
command_5='ps -ef|grep msg_sender|grep -v grep|awk "{print $2}"| xargs kill -9'
cd /home/data/ansible/ && ansible-playbook playbook-standard.yaml --extra-vars "{'host':'$target', 'tar_name':'$tar_name', 'target_name':'$target_name', 'command_1':'$command_1', 'command_2':'$command_2', 'command_3':'$command_3', 'command_4':'$command_4', 'command_5':'$command_5'}"
fi
if test $environ == Online
then
for target in $(echo $server | sed "s/,/ /g")
do
sed -i "s/server_host=.*/server_host=$target/g" $msg_file/msg_sender_$compile_version/conf/msg_sender.ini
if [ -f msg_sender_$compile_version.tar ]; then rm -rf msg_sender_$compile_version.tar; fi
tar -cvf msg_sender_$version.tar msg_sender_$compile_version/
tar_name="/home/data/workspace-jenkins/deploy_msg_sender_release/msg_sender_$compile_version.tar"
command_1="echo ok"
command_2="echo ok"
command_3="cd $target_name && tar -xvf msg_sender_$compile_version.tar"
command_4="cd $target_name && ln -snf msg_sender_$compile_version msg_sender"
command_5="supervisorctl restart msg_sender"
cd /home/data/ansible/ && ansible-playbook playbook-standard.yaml --extra-vars "{'host':'$target', 'tar_name':'$tar_name', 'target_name':'$target_name', 'command_1':'$command_1', 'command_2':'$command_2', 'command_3':'$command_3', 'command_4':'$command_4', 'command_5':'$command_5'}"
done
fi