On each commit, I want to send email with the commit details to a list of emails.
This is necessary to keep everyone involved updated. We are using subversion version
control system on windows, we use cygwin extensively to automate frequent tasks.
Here are the steps to do so:
Environment:
– Windows XP Service Pack 2
– Cygwin DLL release version is 1.5.23-2
– email version 2.5.0
– subversion 1.0.6
Sending email:
– The email.exe tool is a nice small tool to send email using sendmail or using other
SMTP server, I use it to send through our company SMTP server.
– First install cygwin, and you must select additional email tool from the email group.
After installation you will have a shortcut on your Desktop.
After download and installation are OK, you need to configure the email tool before using it.
>From now on, I will put $ before each command line, simply this is the bash prompt. You get bash prompt
by running cygwin shortcut on your PC Desktop.
$ email-config
You will be prompted with a series of questions, answer it to setup the email configuration file.
Please enter your From: name (e.g., John Doe) [Your Real Name]:
Please enter your From: email address [yourlogin@example.com]:
Please enter your Reply-to: email address []:
Enter 1 to use sendmail or 2 to use a SMTP server [1]:
Please enter the address of your SMTP server [127.0.0.1]:
Please enter the SMTP port number [25]:
Please select SMTP authentication (1 for none, 2 for LOGIN, 3 for PLAIN) [1]:
Please enter your SMTP username []:
Please enter your SMTP password []:
$
You can look at /etc/email/email.conf to review your selections and update them as needed.
You can have a look at email man pages by typing, it will show you all the switched used by email tool.
$man email
you can test by sending email to yourself:
$echo “This is a test email body message” > email.txt
$email -s “subject test 1” me@mycompany.com < email.txt
– The first line create file email.txt with the string “This is a test email body message”, of course you can use your favorite editor.
– The second line will just send the email taking the email body from the input stream through “<email.txt”
Now we need to catch svn commit to generate helpful message about the commit and send to email list.
Edit the file c:svnreposmyprojecthookpost-commit.bat using your favorite editor, I assume you locate your repository on c:svnreposmyproject
Add the following lines to it:
SET PATH=%PATH%;c:cygwinbin;C:subversionbin;
svn log -v -r “%1” svn://rd-cdma1/myproject > email.txt
svnlook diff “c:svnreposmyproject” -r “%1” >> email.txt
email -s “Subversion – %2 – %1” email1@company.com,email2@company.com < email.txt
– The PATH environement variable must be set to your programms pathes, I assume c:cygwinbin;C:subversionbin; You must use the correct values that match your system.
– The post-commit.bat will be called every time someone committed new code, this is per subversion implementation.
– %1 is the repository name, automatically passed to the post-commit.bat from subversion.
– %2 is the revision number, automatically passed to the post-commit.bat from subversion.
– > is the redirection operator used to create and append the output to a file.
– >> is the redirection operator used to append at the end of file.
– We use hard coded repository path and URL as the passed parameter %1 has backslashes which doesn’t work on Windows.
Conclusion:
Using command line tools is very helpful in automating tasks, many of the tasks done by admins requires automation, although GUI is very easy to use at first, you will continue doing things manually. command line give you powerful ways to automate new tasks without developing code which takes much more time.
Resources:
– Get cygwin from http://www.cygwin.com/
– Get subversion from http://subversion.tigris.org/