Jenkins + SVN搭建php持续集成
目标需求
开发提交代码到SVN,jenkins在分发服务器上执行'svn update',分发服务器在把代码同步到webserver,实现持续集成
流程
配置jenkins
一、jenkins所需插件
Ant Plugin bouncycastle API Plugin Branch API Plugin build timeout plugin Credentials Binding Plugin Credentials Plugin CVS Plug-in Display URL API Durable Task Plugin Email Extension Plugin Email Extension Template Plugin External Monitor Job Type Plugin Folders Plugin Git client plugin Git plugin GIT server Plugin GitHub API Plugin GitHub Branch Source Plugin GitHub Organization Folder Plugin GitHub plugin Gradle Plugin Hudson WebSVN2 plugin Icon Shim Plugin Javadoc Plugin JavaScript GUI Lib: Handlebars bundle plugin JavaScript GUI Lib: jQuery bundles (jQuery and jQuery UI) plugin JavaScript GUI Lib: Moment.js bundle plugin JUnit Plugin LDAP Plugin Mailer Plugin MapDB API Plugin Matrix Authorization Strategy Plugin Matrix Project Plugin OWASP Markup Formatter Plugin PAM Authentication plugin Pipeline Pipeline Graph Analysis Plugin Pipeline: API Pipeline: Basic Steps Pipeline: Build Step Pipeline: Groovy Pipeline: Input Step Pipeline: Job Pipeline: Milestone Step Pipeline: Multibranch Pipeline: Nodes and Processes Pipeline: REST API Plugin Pipeline: SCM Step Pipeline: Shared Groovy Libraries Pipeline: Stage Step Pipeline: Stage View Plugin Pipeline: Step API Pipeline: Supporting APIs Plain Credentials Plugin Publish Over FTP Publish Over SSH Resource Disposer Plugin SCM API Plugin Script Security Plugin SSH Credentials Plugin SSH plugin SSH Slaves plugin SSH2 Easy Plugin Structs Plugin Subversion Plug-in Subversion Revert Plugin SVN 1.3 Compatibility Plugin SVN 1.4 Compatibility Plugin SVN Publisher plugin svnmerge plugin Terminate ssh processes Timestamper Token Macro Plugin Tracking SVN Plugin Windows Slaves Plugin Workspace Cleanup Plugin
二、配置jenkins的SSH remote hosts
目的:由于jenkins服务器需要登录到分发服务器,所以得配置一下
jenkins首页--系统管理--系统设置
三、配置一个项目
配置代码仓库
配置构建
配置构建后操作,实现构建完成发邮件
四、脚本
分发服务器:项目脚本--wx.sh
vim /alidata1/shell/wx.sh
#!/bin/bash ip="231.201.53.173 221.201.116.12" local_dir_wx="/alidata1/project/wx" target_dir_wx="/opt/www" function wx(){ #实现把代码从分发服务器同步到web服务器 for i in $ip;do rsync -pav -e"ssh -p7789" --delete --exclude=cache --exclude=logs --exclude=.svn --exclude="database.php" $local_dir_wx root@$i:$target_dir_wx >> /dev/null done } #备份并删除源代码 ssh -p7789 root@231.201.53.173 'sh /alidata1/shell/backup_project.sh wx' #在web服务器上执行,把源代码备份 ssh -p7789 root@221.201.116.12 'sh /alidata1/shell/backup_project.sh wx' #rsync wx_project bj1 to bj2&bj4 wx
web服务器:备份脚本
vim /alidata1/shell/backup_project.sh
#!/bin/bash date1=`date +"%F-%H:%M"` src=/opt/www function wx(){ cd $src tar -czvf /alidata1/rollback_project/wx/wx_$date1.tar.gz ./wx/* } function api3(){ cd $src tar -czvf /alidata1/rollback_project/api3/api3_$date1.tar.gz ./api3/* } function admin(){ cd $src tar -czvf /alidata1/rollback_project/admin/admin_$date1.tar.gz ./admin/* } function activity(){ cd /alidata1/www/timecash22 tar -czvf /alidata1/rollback_project/activity/activity_$date1.tar.gz ./activity/* } if [ $1 == "wx" ] then wx elif [ $1 == "api3" ] then api3 elif [ $1 == "admin" ] then admin elif [ $1 == "activity" ] then activity else break fi