当前位置: 首页 > 科技观察

基于jenkins结合git的多服务器批量发布web程序

时间:2023-03-21 16:08:16 科技观察

由于前阵子发了几篇基于jenkins部署web程序的博文,这里就基于svn作为版本库进行讲解。这段时间有朋友问我将git作为版本库与jenkins结合实现程序发布的解决方案,比如选择svn标签指定程序版本。由于时间原因,本文不再过多赘述,读者可以自行揣摩!给大家看下我目前部署到生产环境使用的jenkins截图!下面是配置截图:经过测试,git参数插件不能满足我们的需求,所以只能自己在jenkins中创建标签列表。添加编写步骤如图:自己写一个可扩展的下拉菜单,通过程序生成指定git版本下程序的tags列表。下面是程序的源码管理。在git存储库url中添加我们程序的git地址。Everythingworks:注意我们此时选择的是master版本,也就是说我的程序都是稳定版(开发过程中使用git-flow进程控制版本开发过程)。签出到指定标签:这一步很重要:我们已经实现了jenkins和git的整合!这也是前段时间发布的部署系列中svn和git的区别!至于部分,没有变化!jenkins下的git插件安装网上有很多,这里就不介绍了!需要注意的是gittaglist这个功能可以根据自己的需要开发!下面是我根据自己的需要实现的:先给出程序结构图:$arr=explode("/",$giturl);$names=$arr[count]($arrname)=explode(".",$names);$name=$namearr[0];$重建=真;$tagpath="/var/www/tags/list/$name";如果(file_exists($tagpath)){$content=file_get_contents($tagpath);$tags=explode("\n",$content);//取消链接($标签路径);取消设置($标签[计数($标签)-1]);如果(计数($tags)>0){$tags=array_reverse($tags);echo"tags=".implode(",",$tags);}else{echo"tags=notags";}$ctime=filectime($tagpath);$现在=时间();$ti=$现在-$ctime;如果($ti<60){$rebuild=false;}}else{echo"tags=Isloadingtags;pleasetryagainlater";}if($rebuild){$cmd="echo$name$giturl>/var/www/tags/info/$name";exec($cmd,$info,$rebt);}?>inotify.sh#!/bin/bash#createbylhb#date2014-02-08#monitorfilechangeworkplace=/var/www/tagssrc=$workplace/info/lists=$workplace/list/usr/bin/inotifywait-mrq--timefmt'%d/%m/%y%H:%复制代码M'--format'%T%w%f%e'-eclose_write$src\|whilereadfiledofn=`echo$file|awk'{print$3}'`arr=(`cat$fn|awk'{print$1,$2}'`)pro_name=${arr[0]}pro_url=${arr[1]}#echo$pro_name#echo$pro_url/bin/bash$workplace/get_tags.sh$pro_name$pro_url>$lists/$pro_namechownwww-data:www-data$lists/$pro_nameecho$?doneget_tags.sh#!/bin/bash#createbylhb#date2014-02-08#getgitcodetaglistcodepath=/tmp/$1[-d"$codepath"]||{cd/tmp//usr/bin/gitclone$2&>/dev/null}cd$codepath/usr/bin/gitpull&>/dev/null/usr/bin/gittagrm-rf$codepath执行shell脚本:有不懂的可以参考我的部署系列文章或者在线交流!博客地址:http://birdinroom.blog.51cto.com/7740375/1404930