Tuesday, January 18, 2011

Enable Mail Notification for CVS Commit on CVS Server

Ever wanted to be notified by email to know about who has committed which files and when in specific project in CVS ? Well, Following is the configuration and procedure to enable email notification on CVS Server for cvs commit.

Step 1 : Add the following line in " loginfo" file in the respective CVSROOT ( e.g. /home/cvs/CVSROOT/loginfo) to enable logging of commit for the respective repository

^repositoryname             (echo "At `date`, `whoami` has modified/added following file(s)."; echo "New Versions are :" %v . ; cat ; ) | grep -v -w "In directory " >> /var/log/cvslog/commitlog

In above line " ^repositoryname " is a repository name for which you want to enable logging. The remainder line is containing the command or filter program to execute whenever any matches found ( i.e. any commit has been made to the specified repository ) . Explanations for each switch used in above command are as follows.

        "  s = file name "
        "  V = old version number (pre-checkin) "
        "  v = new version number (post-checkin) "

So, in simple words what above line will do is whenever any user make cvs commit to that repository, it will collect information such as username, date and time when it is committed, new version numbers, names, etc. and put it into one file ( /var/log/cvslog/commitlog in this case) and it will append the same file for all commit made to that repository

Now we will set one script to simply send that log file to the specified email as shown in below and we will put this script in crontab to run at 6:00 PM everyday

Step 2 :Create cvsmail.csh file on your CVS Server linux machine and add following contents into it and save it

[root@CVS ~]# vi /home/cvs/cvsmail.csh

if ( `ll /var/log/cvslog | grep -w commitlog | wc -l` > 0 ) mail -s " CVS Commit Notification for repositoryname" abc@example.com < /var/log/cvslog/commitlog && if ( `ll /var/log/cvslog | grep -w commitlog | wc -l` > 0 ) rm -rf /var/log/cvslog/commitlog

[root@CVS ~]# chmod +x /home/cvs/cvsmail.csh
[root@CVS ~]# su - cvs

Step 3 :Create Crontab entry to schedule email notification at 6:00 PM daily. add following contents into it and save it.

[cvs@CVS ~]$ crontab -e

00  18 * * * /home/cvs/cvsmail.csh

[cvs@CVS ~]$

What above line will do is it will check if any commit made to any file in specified repository by checking if commitlog log file exists or not , if it is then it will send that log file to the specified email id and then remove that log file. Mail will be sent from id cvs@cvs.com


1 comment: