Pete Freitag Pete Freitag

Using Subversion Hooks to send out build emails

Updated on November 30, 2023
By Pete Freitag
coldfusionjavamiscbooks

The subversion version control system has a wonderfully handy feature called hooks. Hooks are essentially scripts that are triggered by a version control event (such as a commits, or revision property changes).

Subversion Hooks are located in your repository directory (so if you have multiple repositories you have to setup hooks for each one) in a directory called hooks, perhaps something like this: /home/svn/projectName/hooks. There are template files (.tmpl) in the directory for each event (these files are just examples). The events are:

  • start-commit - run before commit transaction begins, can be used to do special permission checking
  • pre-commit - run at the end of the transaction, but before commit. Often used to validate things such as a non zero length log message.
  • post-commit - runs after the transaction has been committed. Can be used for sending emails, or backing up repository.
  • pre-revprop-change - runs before a revision property change. Can be used to check permissions.
  • post-revprop-change - runs after a revision property change. Can be used to email or backup these changes.

In your hooks directory you will find a .tmpl file with each of the event names, if you want to enable one of the hooks, copy the template file (without the .tmpl extension) and make it executable.

Note: On windows you need to rename the .tmpl file with an extension that is executable by windows such as an exe or bat file.

If you want to send out a build email on post-commit copy the post-commit.tmpl file to post-commit and make it executable. Edit the file, and add your email addresses.

Subversion comes with a few other pre-built hook scripts, there is a hot-backup.py script that can be used to make hot backups of your repository after commits.

You can find more info about this in the Version control with Subversion book (ISBN 0596004486) which can also be found here

As with any server, you should also make sure your subversion server is patched for security vulnerabilities. A good way to keep updated on subversion vulnerabilities is with stack.watch. It will help you by sending you an email when new vulnerabilities are published.



subversion version control hooks

Using Subversion Hooks to send out build emails was first published on February 23, 2005.

If you like reading about subversion, version control, or hooks then you might also like:

FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.

CFBreak
The weekly newsletter for the CFML Community


Comments

You are describing how to send out emails containing the results of a svn commit, not a *build* of the code in the repository.

But your blog title mentions "build emails". How can you use svn hooks to email results of a build?

Did I miss something?
by Aslak Hellesoy on 02/24/2005 at 1:58:17 AM UTC
Hi Aslak,

We actually use subversion hooks to do just that, we send the results of the ant build script and also the svn commit. Basically what you need to do is write the results of your build to a file, and include the contents of the file in the email
by Pete Freitag on 02/24/2005 at 8:35:30 AM UTC
Fred, thanks for your reply. Got it.

AFAIK, the various hook scripts execute in a synchronous fashion, keeping the svn client blocked until everything is complete.

In other words, I'm assuming your svn client is blocked until your build is complete (correct me if I'm wrong).

Since commit transactions now become potentially very long (a build of a project typically takes from 10 secs to 30 minutes) - how does this impact your work?

Does svn allow concurrent commits? (I.e. can Sue commit while Fred's commit is in process?) If concurrent commits are not possible, wouldn't your setup potentially cause developers to have to queue up in order to commit their changes?
by Aslak Hellesoy on 02/24/2005 at 9:54:52 AM UTC
If you run with a post-commit hook, your svn client returns, and the build goes on in the background, and emails you when its done.
by Pete Freitag on 02/24/2005 at 10:25:18 AM UTC
Aslak, The client does not hang, so subversion must fork a new process or thread to handle the post-commit operations.
by Pete Freitag on 05/09/2005 at 12:19:16 PM UTC
I copied the post-commit template and chmod +x to make it an executable. I also added my email to the post-commit file. I've tried commiting a changed file in the svn repository, but I still don't receive an email about the change.
by Jennifer on 10/25/2005 at 5:02:56 PM UTC
Hello,
Can any one point me to what is needed to enable the revprop change hook when running the SVN server on Windows?
by Mark Andrews on 02/23/2006 at 6:06:09 AM UTC
i followed all the steps and the subversion did send a mail when i commit a change, but i found that the from segment of the mail had been changed to something else.How can i change it back to the original one?
by xutm on 10/19/2006 at 12:18:09 AM UTC
For windows users, I've created an application that can handle pre-commit and post-commit Subversion hooks. The pre-commit hooks allow you to control what goes into your repository as well as validate commit messages. The post-commit sends out nicely formatted e-mails. This is a SourceForge.net project but is summarized on my site: http://mckechney.com/SubversionNotifyForWindows
by mmckechney on 12/19/2007 at 8:25:15 PM UTC