Linux 如何安装 svn post-commit 钩子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7577234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to install svn post-commit hook
提问by johnsam
I am running SVN on Linux. I was hoping to run auto deployment once committed. Based on my searching, it looks like svn post-commit might do the trick. But I couldn't find SVN post-commit from my SVN installation. So I wonder if it's a separate install? Is there any SVN post-commit hook that I can download and install?
我在 Linux 上运行 SVN。我希望一旦提交就运行自动部署。根据我的搜索,看起来 svn post-commit 可以解决问题。但是我无法从我的 SVN 安装中找到 SVN post-commit。所以我想知道它是否是单独的安装?有没有我可以下载和安装的 SVN post-commit 钩子?
采纳答案by zhongshu
It's not a separate install. In your respository directory, there is a 'hooks' dir. You can find post-commit.tmpl, just modify the file and rename it to executable file according your os type.
这不是单独的安装。在您的存储库目录中,有一个“钩子”目录。你可以找到post-commit.tmpl,根据你的操作系统类型修改文件并重命名为可执行文件即可。
回答by David W.
First, you probably don't want to do this as a post-commit. The reason is that you don't want to do anything that takes too long to do in a hook because the user has to wait for the hook to complete before they can continue.
首先,您可能不想在提交后执行此操作。原因是您不想在钩子中做任何需要太长时间才能完成的事情,因为用户必须等待钩子完成才能继续。
To answer your question, take a look at the repository directory on your server, you should see the following directories and files:
要回答您的问题,请查看您服务器上的存储库目录,您应该会看到以下目录和文件:
- README.txt
- conf
- db
- format
- hooks
- locks
- 自述文件
- 配置文件
- D b
- 格式
- 钩子
- 锁
One of the directories is called hooks
. Take a look in this directory:
其中一个目录称为hooks
. 看看这个目录:
- post-commit.tmpl
- post-lock.tmpl
- post-revprop-change.tmpl
- post-unlock.tmpl
- pre-commit.tmpl
- pre-lock.tmpl
- pre-revprop-change.tmpl
- pre-unlock.tmpl
- start-commit.tmpl
- 提交后.tmpl
- 锁后.tmpl
- post-revprop-change.tmpl
- 解锁后.tmpl
- 预提交.tmpl
- 预锁.tmpl
- pre-revprop-change.tmpl
- 预解锁.tmpl
- 开始提交.tmpl
These are templates for the various hooks. You'll see these are all simple BASH/Korn/Bourne shell scripts. You'll be using the svnlook
command to get information about the revision or transaction (if pre-commit hook) that your user just committed.
这些是各种钩子的模板。您会看到这些都是简单的 BASH/Korn/Bourne shell 脚本。您将使用该svnlook
命令来获取有关您的用户刚刚提交的修订或事务(如果是预提交挂钩)的信息。
What you would do is run the command svnlook changed
to see what was changed, then based upon this information, you'll have to fetch the file, and deploy it. This means you'll have to create a working directory and do a checkout. Imagine a developer doing a checkin, and then waiting for your post-commit hook to do a checkout and deployment.
您要做的是运行命令svnlook changed
以查看更改的内容,然后根据此信息,您必须获取文件并部署它。这意味着您必须创建一个工作目录并进行结帐。想象一个开发人员进行签入,然后等待您的提交后挂钩进行签出和部署。
What you would be better off doing is getting something like Jenkinsto do your post commit tasks. Jenkins is normally a continuous build server. Whenever someone does a commit, Jenkins does a checkout on that project and does the build. It can run all sorts of tests, and then email the developers if there are any problems.
你最好做的是让Jenkins来完成你的提交后任务。Jenkins 通常是一个持续构建服务器。每当有人提交时,Jenkins 都会对该项目进行检出并进行构建。它可以运行各种测试,如果有任何问题,然后通过电子邮件发送给开发人员。
However, it can also simply do a checkout and deployment if you really have nothing to build. Jenkins uses Java 1.6 to run, but otherwise, it's pretty easy to install and use. It's all menu driven, and you don't need to know how to create XML files or write any programs to use it.
但是,如果您真的没有什么可构建的,它也可以简单地进行检出和部署。Jenkins 使用 Java 1.6 来运行,但除此之外,它的安装和使用非常容易。它完全由菜单驱动,您不需要知道如何创建 XML 文件或编写任何程序来使用它。
So, take a look at Jenkins and see about doing your deployments from there. This way, your developers can continue their work while Jenkins handles the deployments. And, you can have Jenkins send out an email, an IM, Tweet, or even change a traffic light from green to red if there is an issue with the deployment.
所以,看看 Jenkins,看看如何从那里进行部署。这样,您的开发人员可以在 Jenkins 处理部署的同时继续他们的工作。而且,如果部署出现问题,您可以让 Jenkins 发送电子邮件、即时消息、推文,甚至将交通灯从绿色更改为红色。