Thursday, June 25, 2009

Use Post-Commit Hook in Subversion for Email Notification

  • Sector: Subversion (SVN) Management
  • Challenge: Instead of react to the request from development team to build and push the code, Intelligent Build Manager would like to monitor the commit activities and be notified by email automatically.
  • Client: Build manager
  • Solution:
    • Write a Post-Commit hook on Subversion server which will be triggered when a commit happened
    • Write a VBScript file to
      • Send email notification
      • Write a record to the BuildManager Database (development environment of our SSAS DW)
  • SVN Hooks:
    • The post-commit hook is invoked after a commit.
    • Subversion runs this hook by invoking a bat file under \SVN\REPOS\repository name\hooks\post-commit.bat with the following ordered arguments:
      • [1] REPOS-PATH (the path to this repository)
      • [2] REV (the number of the revision just committed)
    • The default working directory for the invocation is undefined, so the program should set one explicitly if it cares.
    • Because the commit has already completed and cannot be undone, the exit code of the hook program is ignored.
    • Note that 'post-commit' must be executable by the user(s) who will invoke it (typically the user httpd runs as), and that user must have filesystem-level permission to access the repository.
    • The hook program does not inherit the environment of its parent process. For example, a common problem is for the PATH environment variable to not be set to its usual value.
  • VB Scripting:
    • In post-commit.bat, you can do as simple as the following line to basically pass those 2 parameters:\_BuildManager\Bin\Notification_Commit.vbs "%1" "%2"
    • In Notification_Commit.vbs, use svnlook to get information then send emails through CDO object
  • Results:
    • Commit becomes a noticeable and traceable activity
    • While doing the email notification, this entry point also becomes a wonderful place to inject Subversion data to our BuildManager Data Warehouse. Save another ETL time and resources
    • Notification from "dev" branch becomes a proactive way to check progress and predict trunk commit and thus the progress of the working tickets.
    • By monitoring the flow from trunk commit to pull finish can usually help to detect the possible issues with pulling/compiling.
  • Lessions: Through multiple dimension approach, Build Manager finally can feel the move of the whole dynamic environment thus becomes a Intelligent Build Manager.

0 comments:

Post a Comment