2

I'm running VisualSVN on a Windows server.

I'm trying to add a post-commit hook to update our staging project whenever a commit happens.

In VisualSVN, if I type the command in the hook/post-commit dialog, everything works great.

However, if I make a batch file with the exact same command, I get an error that says the post-commit hook has failed. There is no additional information.

My command uses absolute paths.

I've tried putting the batch file in the VisualSVN/bin directory, I get the same error there.

I've made sure VisualSVN has permissions for the directories where the batch file is.

The only thing I can think of is I'm not calling it correctly from VisualSVN. I'm just replacing the svn update command in the hook/post-commit dialog with the batch file name ("c:\VisualSVN\bin\my-batch-file.bat") I've tried it with and without the path (without the path it doesn't find the file at all).

Do I need to use a different syntax in the SVNCommit dialog to call the batch file? What about within the batch file (It just has my svn update command. It works if I run the batch file from the command line.)

Ultimately I want to use a batch file because I want to do a few more things after the commit.

bahrep
  • 29,961
  • 12
  • 103
  • 150
BDW
  • 612
  • 1
  • 8
  • 20

3 Answers3

1

When using VisualSVN > Select the Repo > Properties > Hooks > Post-commit hook. Where is the code I use for Sending an Email then running a script, which has commands I want to customize

 "%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
    commit-notification "%1" -r %2 ^
    --from support@domainname.com --to "support@domainname.com" ^
    --smtp-server mail.domainname.com ^
    --no-diffs ^
    --detailed-subject
    --no-html

set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| C:\ServerScripts\SVNScripts\post-commit-wp.ps1 %1 %2
if errorlevel 1 exit %errorlevel%

The script file is located on C:\ServerScripts\SVNScripts\ post-commit-wp.ps1 and I pass in two VisualSVN variables as %1 and %2

  • %1 = serverpathwithrep
  • %2 = revision number

The script file is written in Windows PowerShell

# PATH TO SVN.EXE
$svn = "C:\Program Files\VisualSVN Server\bin\svn.exe"
$pathtowebistesWP = "c:\websites-wp\"

# STORE HOOK ARGUMENTS INTO FRIENDLY NAMES
$serverpathwithrep = $args[0]
$revision   = $args[1]

# GET DIR NAME ONLY FROM REPO-PATH STRING 
# EXAMPLE: C:\REPOSITORIES\DEVHOOKTEST
# RETURNS 'DEVHOOKTEST'
$dirname = ($serverpathwithrep -split '\\')[-1]

# Combine ServerPath with Dir name
$exportpath = -join($pathtowebistesWP, $dirname);

# BUILD URL TO REPOSITORY
$urepos = $serverpathwithrep -replace "\\", "/"
$url = "file:///$urepos/"


# --------------------------------
# SOME TESTING SCRIPTS
# --------------------------------

# STRING BUILDER PATH + DIRNAME
$name = -join($pathtowebistesWP, "testscript.txt");
# CREATE FILE ON SERVER
New-Item $name -ItemType file
# APPEND TEXT TO FILE
Add-Content $name $pathtowebistesWP
Add-Content $name $exportpath

# --------------------------------


# DO EXPORT REPOSITORY REVISION $REVISION TO THE ExportPath
&"$svn" export -r $revision --force "$url" $exportpath

I added comments to explain each line and what it does. In a nutshell, the scripts:

  • Gets all the parameters
  • Build a local dir path
  • Runs SVN export
  • Places files to a website/publish directory.

Its a simple way of Deploying your newly committed code to a website.

Ravi Ram
  • 24,078
  • 21
  • 82
  • 113
0

I was trying the same thing and found that you also must have the script in the hooks folder.. the bat file that is.

0

Did you try to execute batch file using 'call' command? I mean:

call C:\Script\myscript.bat
Ivan Zhakov
  • 3,981
  • 28
  • 24
  • Then try to add "exit 0" at end of the the script. – Ivan Zhakov Jun 25 '10 at 10:20
  • I have a batch script with two commands call svn cleanup C:\algit\web2py\applications/iRazporedDemo call svn update C:\algit\web2py\applications/iRazporedDemo if I run them on server from cmd it works ok, when I run my svn update from tortoise I get an error post-commit hook failed exit code 0 attempt to write to readonly db – Yebach Nov 03 '14 at 09:50