SVN email notification is important when many programmer involves in software development. For example, you are working on module and other programmers are using that. So if you check-in updated the classes , you have to notify other developers that module has been updated.
SVN provide post commit hook option, there you can add any script or programme that would be execute after SVN commit. Here I will add email notification in post-commit hook script.
I have create a repository in /apps/subversion/hsolite/.
Using ls command you can see default directories created under repository. There is a directory called hooks where you will put you post-commit script. When any user will commit in SVN, post-commit script will be execute.
To send email notification you need find out "mailer.py" and "mailer.conf"
[root@domU-12-31-39-09-29-13 hsolite]# find / -name "mailer.py"
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py
SVN provide post commit hook option, there you can add any script or programme that would be execute after SVN commit. Here I will add email notification in post-commit hook script.
I have create a repository in /apps/subversion/hsolite/.
Using ls command you can see default directories created under repository. There is a directory called hooks where you will put you post-commit script. When any user will commit in SVN, post-commit script will be execute.
To send email notification you need find out "mailer.py" and "mailer.conf"
[root@domU-12-31-39-09-29-13 hsolite]# find / -name "mailer.py"
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py
[root@domU-12-31-39-09-29-13 hsolite]# find / -name "mailer.conf"
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf
Now copy the mailer.py and mailer.conf under /apps/subversion/hsolite/hooks and /apps/subversion/hsolite/ respectively.
[root@domU-12-31-39-09-29-13 hsolite]# cp /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py /apps/subversion/hsolite/hooks/mailer.py
[root@domU-12-31-39-09-29-13 hsolite]# cp /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf /apps/subversion/hsolite//mailer.conf
Now edit the mailer.conf and override following properties
mail_command = /usr/sbin/sendmail
commit_subject_prefix = [svn-myproject]
from_addr = noreply@mydomain.com
to_addr = commits-myproject@mydomain.com # this is a mailing list
Under hooks directory you will find "post-commit.tmpl" that you need to rename to "post-commit".
Replace "post-commit" script contains with the following snippet.
------------------------------------------------
#!/bin/sh
REPOS="$1"
REV="$2"
/apps/subversion/hsolite/hooks/mailer.py commit "$REPOS" "$REV" /apps/subversion/hsolite/mailer.conf
-------------------------------------------------------
Make sure "post-commit" is executable.
[root@domU-12-31-39-09-29-13 hsolite]# chmod +x post-commit
Testing :
Using svnlook yon can get latest revision number.
[root@domU-12-31-39-09-29-13 ~]# svnlook info /apps/subversion/hsolite/
sujankn
2013-08-16 07:41:29 -0400 (Fri, 16 Aug 2013)
0
[root@domU-12-31-39-09-29-13 ~]# svnlook youngest /apps/subversion/hsolite/
2850
Test the hook script:
[root@domU-12-31-39-09-29-13 ~]# REPOS=/apps/subversion/hsolite/
[root@domU-12-31-39-09-29-13 ~]# REV=2850
[root@domU-12-31-39-09-29-13 ~]# "$REPOS"/hooks/mailer.py commit "$REPOS" $REV "$REPOS"/mailer.conf
After run above command you should receive email notification with revision number 2850
[root@domU-12-31-39-09-29-13 ~]# REPOS=/apps/subversion/hsolite/ [root@domU-12-31-39-09-29-13 ~]# REV=2850 [root@domU-12-31-39-09-29-13 ~]# sh $REPOS/hooks/post-commit $REPOS$REV
If post-commit script run successfully then commit some files in SVN then check your email inbox for notification.
Do you like this post? Please link back to this article by copying one of the codes below.
URL: HTML link code: BB (forum) link code:
[ormktuat@nacismktl219 conf]$ sh $REPOS/hooks/post-commit $REPOS$REV
ReplyDeleteTraceback (most recent call last):
File "/u120/svn/Campaign_Builder/hooks/mailer.py", line 1348, in ?
sys.argv[3:3+expected_args])
File "/usr/lib64/python2.4/site-packages/svn/core.py", line 281, in run_app
return func(application_pool, *args, **kw)
File "/u120/svn/Campaign_Builder/hooks/mailer.py", line 81, in main
revision = int(cmd_args[0])
ValueError: invalid literal for int():
Please suggest
Give the space between $REPOS $REV
ReplyDeleteThe correct one:
[ormktuat@nacismktl219 conf]$ sh $REPOS/hooks/post-commit $REPOS $REV
I am jovial you take pride in what you write. It makes you stand way out from many other writers that can not push high-quality content like you. eth notifications
ReplyDelete