SVN Hook to send email after commit

As SVN admin we are asked to send an email to release managers and testers for all the commits made to the repository so that release managers can update their release sheet and testers can do the testing. This is small post-commit hook for SVN which sends out an email to release manager and testers.

#!/bin/sh

REPOS="$1"
REV="$2"

SVNLOOK=/usr/bin/svnlook

auth=`$SVNLOOK author -r $REV $REPOS`
dt=`$SVNLOOK date -r $REV $REPOS | sed 's/,//g'`
changed=`$SVNLOOK changed -r $REV $REPOS`
log=`$SVNLOOK log -r $REV $REPOS`
n=$'n'

LISTID="releasemanagers@yourdomain.com testers@yourdomain.com"

echo "$n $n====Status:PROJECT INTEGRATION svncommit: $DATTIM====$n Changeset [Revision ID ${REV}] by $auth.$n$n On Date $dt.$n$n With Comment $n$log.$n$n Files Changed$n $changed.$n $n" | mailx -s "New Commit in $REPOS" $LISTID

I hope this will be helpful for someone. You can also write SVN Hook to stop commits without comments

6 Comments

  1. hi ,

    can you plz help how to write the script for sending mail from svn when some one commit or delete the files from svn, and which scripting we need to use to send the mail
    111
    111

    • Satish,

      You can use post-commit hook to send an email when some one does a commit.

      On linux machine you can write following script name post-commit.

      [bash]
      #!/bin/sh

      REPOS=”$1″
      REV=”$2″

      SVNLOOK=/usr/bin/svnlook

      auth=`$SVNLOOK author -r $REV $REPOS`
      dt=`$SVNLOOK date -r $REV $REPOS | sed ‘s/,//g’`
      changed=`$SVNLOOK changed -r $REV $REPOS`
      log=`$SVNLOOK log -r $REV $REPOS`
      n=$’n’

      echo -e “$n $n====Status:PROJECT INTEGRATION svncommit: $DATTIM====$n Changeset [Revision ID ${REV}] by $auth.$n$n On Date $dt.$n$n With Comment $n$log.$n$n Files Changed$n $changed.$n $n” | mail -s “SVN Commit” xyz@domain.com

      [/bash]

  2. Hi Mohan
    thank you for the great info .
    could you please suggest how can i get report from two branches
    i have hot fix branch and release branch , how do i get report to check and verify all the user stories are merged from hot fix branch to release branch . report anything not merged.

    Thanks in advance.

    • Hi Madhu,

      Sorry for late reply have been on vacation without internet access. I hope by now you might have solved your problem.

      If not please contact me using the contact forma and we can try to address your problem.

      Regards,

      Mohan

Leave a Reply

Your email address will not be published.


*


CommentLuv badge