svn服务端的自动发布
需求: 当开发人员提交网页代码后,自动化的实现部署到apache服务器。
参考文档:
R1:http://imrannazar.com/Automated-Deployment-with-Subversion
R2:http://stackoverflow.com/questions/777623/subversion-commit-failed-merge-of-file-200-ok
R3:http://juretta.com/log/2007/05/09/svn_can_t_convert_string_from_utf-8_to_native_encoding_/
R4:http://hi.baidu.com/bigeyex/blog/item/9f7ac600e8823319728b65b6.html
实现过程,是使用了svn的一个hook的功能,我们调用了 post-commit 来做一些当提交完成后的操作。
1. 编辑svn代码库服务器上文件: svn/test/hooks/post-commit
#!/bin/sh
REPOS="$1"
REV="$2"
export PATH="/usr/local/svn/bin:$PATH" #由于代码是apache的进程用户www运行,所以需要设置环境变量
export LC_CTYPE=en_US.UTF-8 #防止提交的文件名存在非字母字符。
if (svnlook log -r $REV /home/http/repository/svn/test | grep "auto_deploy" ) #当用户提交时注释中写上"auto_deploy"的时候,就自动部署到apache目录,否则不部署。
then
echo "`date` 'auto depoly command received" >> /tmp/test_svnautocommit.txt #这一行仅作调试使用
svn export "http://192.168.16.48/repo/svn/test/trunk/test_website" /home/http/html/test_website --force
fi
REPOS="$1"
REV="$2"
export PATH="/usr/local/svn/bin:$PATH" #由于代码是apache的进程用户www运行,所以需要设置环境变量
export LC_CTYPE=en_US.UTF-8 #防止提交的文件名存在非字母字符。
if (svnlook log -r $REV /home/http/repository/svn/test | grep "auto_deploy" ) #当用户提交时注释中写上"auto_deploy"的时候,就自动部署到apache目录,否则不部署。
then
echo "`date` 'auto depoly command received" >> /tmp/test_svnautocommit.txt #这一行仅作调试使用
svn export "http://192.168.16.48/repo/svn/test/trunk/test_website" /home/http/html/test_website --force
fi
2. 在客户端测试,并且要在comment中加入 auto_deploy,否则不会触发自动部署的操作。