自动svn update远程目录

利用svn的hooks,可以做到当有commit时自动svn update远程目录,方法如下:

1.在你要自动更新的服务器上根目录上编写一个svn.php文件,内容如下:

<?php

error_reporting(E_ALL);
$result = array();
header(“Cache-Control:no-cache,must-revalidate”);
exec(‘/usr/bin/svn update /data/website/xxxx –username ***** –password **** –no-auth-cache 2>&1’, $result);
echo “<pre>”;
echo “svn update如下内容:\n”;
if(is_array($result)){
foreach($result as $row){
echo $row.”\n”;
}
}
echo “</pre>”;

?>

其中,/data/website/xxxx为你要实现自动更新的代码目录,–username后接你的svn用户名,–password后接你的svn密码。

由于是通过http方式执行svn update,因此如果你的nginx或apache是用nobody用户的话,则需要chown nobody:nobody /data/websitexxxx -R

做好以上设置后,请在地址栏打开http://域名或ip/svn.php,看是否运行正常。

2.打开你代码的subversion库目录,将hooks目录下的post-commit.tmpl改为post-commit,同时chmod 755 post-commit

3.编辑post-commit 写上wget -q http://域名或ip/svn.php 2>&1并保存

测试:向你的版本库提交一次改动,然后到你的远程服务器上看是否自动更新了。


相关评论

暂无评论

我要评论