Posts Tagged ‘send email’
When you are in a big team of developers and using continuous integration, it really helps to receive an email when someone adds code to the repository. One way to do this is to create a ‘post-commit’ hook in your subversion repository.
Locate your repository on the server and find the folder ‘hooks’. Here you can create a .bat file which will contain the necessary script to send the email.
Lets go ahead and create a file called ‘post-commit.bat’. All you need to put in this file is the following:
C:\[PATH-TO-REPOSITORY]\sendmail.bat %1 %2
We will create another batch file that will, in this case, read a list of comma seperated email addresses from a file called ‘email.txt’. You may also just add the emails directly in the batch file, but I find it easier to manage with a simple txt file. (note that ‘Blat’ is being used as email tool, but you can use any command line email tool you prefer)
Below is the contents of the sendmail.bat file:
SET REPOS=%1 SET REV=%2 SET LPath=C:\svn_repository\ ECHO Repo: %REPOS% >> %LPath%log.txt ECHO Rev: %REV% >> %LPath%log.txt SET LOG_FILE=%LPath%svnfileR-%REV%.txt SET LOG_FILE1=%LPath%svnfileR1-%REV%.txt SET LOG_FILE2=%LPath%svnfileR2-%REV%.txt SET AUT_FILE=%LPath%svnfileA-%REV%.txt "C:Program FilesCollabNet Subversion Server"\svnlook info -r %REV% %REPOS% > %LOG_FILE1% "C:Program FilesCollabNet Subversion Server"\svnlook changed -r %REV% %REPOS% > %LOG_FILE2% copy %LOG_FILE1%+%LPath%spacer.txt+%LOG_FILE2%+%LPath%spacer.txt+%LOG_FILE% "C:Program FilesCollabNet Subversion Server"\svnlook author -r %REV% %REPOS% > %AUT_FILE% REM SET THE AUTHOR FROM THE FILE. FOR /F %%A IN (%AUT_FILE%) DO SET AUTHOR=%%A SET EMAILFILE=%LPath%emails.txt FOR /F %%A IN (%EMAILFILE%) DO SET EMAILS=%%A ECHO Executing: %LPath%blat svnfileR1-%REV%.txt -to %EMAILS% -s "Repository Commit by %AUTHOR% New Revision: %REV%" >> %LPath%log.txt %LPath%blat svnfileR1-%REV%.txt -to %EMAILS% -s "Repository Commit by %AUTHOR% on %REPOS% @ %REV%" >> %LPath%log.txt -server L060 -f BuildMaster@someplace.com del %LOG_FILE% del %LOG_FILE1% del %LOG_FILE2% del %AUT_FILE%