svnbatch-filefindstrpost-commit-hooksvnlook

Batch script to search for a particular string in SVN revision file


I need some help with windows batch script

What am i trying to achieve:

What i have tried:

set REVNO=$(svnlook youngest D:\Subversion\...)
set REVURL=D:\Subversion\...\db\revprops\0\
findstr /m "string_I_am_searching_for" %REVURL%%REVNO%
if %errorlevel%==0 (
  start http://webpage
)

Why am i trying to do this:

I want to start Hudson CI automatic test after a commit that has a particular string in message (ex. Autobuild: true)

I am not able to debug my code, since i am unfamiliar with Windows batch scripting

In my script I used:

I would not be surprised if my small script has semantic problems as well as syntactic problems, because, as I have already mentioned, I haven't done that much of batch scripting before

I have no requirements, no specifications, so the script may be implemented in any way possible. So i am open for suggestions

P.S. I have read also that using overweight procedures on post-commit is not a good idea, because svn does not return controls back to the user until it is done with everything -> This is not a big problem

EDIT: I found by side testing that i didn't really aquire the youngest revision number, but rather used the command string. SO after googling a little more i found that it is not that easy in windows to call some command and store the result in variable. So i have decided to use file to store intermediate results.

This is what i have tried:

cd D:\Subversion\...\hooks
SET OUTPUT=testing
FOR /F "tokens=*" %a in ('revision.bat') do ( SET OUTPUT=%a )
findstr /m "o" D:\Subversion\...\db\revprops\0\%a
if %errorlevel%==0 (
  start http://webpage
)

in revision.bat:

svnlook youngest D:\Subversion\...

Now i get this error in SVN:

post-commit hook failed (exit code 255) with output:
a" ) was unexpected at this time.

I believe it is because i create variable a in a wrong place at wrong time. But I do not get this error if i run bat file manually


Solution

  • Found one way to do it - to store intermediate function in .bat file:

    post-commit.bat

    @ECHO OFF
    cd D:\Subversion\...\hooks
    SET OUTPUT
    FOR /F "tokens=*" %%a in ('revision.bat') do ( SET OUTPUT=%%a )
    findstr /m "o" D:\Subversion\...\db\revprops\0\%OUTPUT%
    if %errorlevel%==0 (
      start http://website
    )
    

    revision.bat

    svnlook youngest D:\Subversion\...
    

    This is rather a workaround than a solution in my opinion

    Thanks to: https://serverfault.com/questions/245679/store-output-of-windows-command-in-batch-file