Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install svn post-commit hook

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?

like image 373
johnsam Avatar asked Sep 28 '11 00:09

johnsam


People also ask

What is post-commit hook in SVN?

The post-commit hook is run after the transaction is committed and a new revision is created. Most people use this hook to send out descriptive emails about the commit or to notify some other tool (such as an issue tracker) that a commit has happened. Some configurations also use this hook to trigger backup processes.

How add pre-commit to SVN?

To set up a hook, you need only to put the script in a hooks directory in your Subversion repository directory (e.g. /home/username/svn/project/hooks). This directory should already exist if your repository was created in the usual way, and will have a couple of example (template) files ending .

What is pre-commit hook in SVN?

The pre-commit hook gives you an opportunity to catch the transaction just before it becomes a revision. Subversion passes this hook two parameters: the path to the root of the repository. the transaction identifier.


1 Answers

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

One of the directories is called hooks. Take a look in this directory:

  • 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

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.

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.

What you would be better off doing is getting something like Jenkins to 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.

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.

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.

like image 73
David W. Avatar answered Oct 13 '22 00:10

David W.