Click here to Skip to main content
13,052,900 members (62,695 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 21 Sep 2009

SVN pre-commit hook in VBScript

, 21 Sep 2009
Rate this:
Please Sign up or sign in to vote.
A pre-commit hook for SVN to validate commits against JIRA.


Subversion’s hook scripts provide a powerful and flexible way to associate actions with repository events. For example, the pre-commit hook allows you to check and possibly abort a transaction before it actually gets committed. This article describes how to write such a hook in VBScript® and test whether the committer has supplied a commit message and that the message contains a valid issue ID. The issue tracking system used for integration is JIRA®.

Creating the Hook Script

When you install Subversion, it also installs sample hook scripts. These sample scripts are located in the REPOS_PATH\hooks directory. For example, the pre-commit template is in PATH_TO_REPOS/hooks/pre-commit.tmpl. These templates contain instructions on what the hook script does and what parameters it can expect.


The hook file must be an executable. Windows uses file extensions to determine whether or not a program is an executable, so you would need to supply a program whose base name is the name of the hook, and whose extension is one of the special extensions recognized by Windows for executable programs, such as .exe or .com for programs, and .bat for batch files.

The Pre-commit Hook

The pre-commit hook gives you an opportunity to catch the transaction just before it becomes a revision. Typically, this hook is used to protect against commits that are disallowed due to content or location (for example, your organisation might require that all commits to a certain branch include a ticket number from the bug tracker, or that the incoming log message is non-empty). Subversion passes this hook two parameters:

  1. The path to the root of the repository
  2. The transaction identifier

The pre-commit can fail the transaction by printing an informative message to standard error and returning a non-zero value. A return code of zero allows the transaction to complete successfully.

The Hook Script

The hook script enforces the following rules:

  • Non empty commit message.
  • Commit message must begin with an Issue ID followed by a space and hyphen.
  • The Issue ID specified must be a valid issue in the Issue System (JIRA).
  • The Issue must have been assigned to the committer.

JIRA Integration

The integration with JIRA is done via a Web Service using SOAP messages. This of course requires that the XMLRPC plug-in be enabled on the JIRA server. The script makes use of the MSXML.HTTP object to invoke the JIRA Web Service. The commit log message and the committer are found using the svnlook.exe program which comes with the Subversion software. The Web Service invocation is done by a class named WebService which is actually an adaptation of the code published at CDYNE Wiki. (The code found on this site is good enough to make a POST request, but fails to invoke a SOAP enabled Web Service.) The code calls the following methods in the JIRA Web Service:

  • login - This method must be called to ensure that we get an authentication token. The token returned by this method is required in subsequent calls. This method takes the following two parameters, and upon successful logon, returns the authentication token:
    1. in0 - The user name
    2. in1 - The plain text user password
  • getIssue - This method is used to retrieve the issue details given its id. This method takes the following two parameters, and returns the issue details if the requesting user has view permissions and the issue with the supplied ID exists:
    1. in0 - The authentication token
    2. in1 - The issue ID
  • logout - This method is used to logout the user. This method takes only one parameter, namely the authentication token.

The actual error is conveyed back to the user by writing the error text on StdErr. This allows the committer to see why his/her commit is denied.


As mentioned earlier, the Subversion server is capable of calling the executable scripts only. Since the pre-commit hook is written in VBScript, we need a driving script. Here is the driving script:

SET PATH=C:\Windows;C:\Windows\system32;D:\SCC\SVN146\bin;
cscript.exe //NoLogo H:\SVNRepo\docman\hooks\pre-commit.wsf %1 %2




  • 4/11/2008 - The first version released on my blog.


This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


About the Author

Prasad Khandekar
Software Developer (Senior) Freelancer
India India
I am a software professional with over 20 years of commercial business applications design and development experience.

My programming experience includes Java, Spring, .NET, Classic VB & ASP, Scripting, Power Builder, PHP, Magic & far far ago FoxPro, C, Assembly and COBOL.

From last 11 years I am mostly working with Java Technology. I am currently available to take up new assignments.

You may also be interested in...

Comments and Discussions

GeneralUsing the Subversion pre-commit Hook with PC lint Pin
Chai Chin Leong21-Dec-10 14:43
memberChai Chin Leong21-Dec-10 14:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 21 Sep 2009
Article Copyright 2009 by Prasad Khandekar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid