I’m setting up a testbed development landscape with the Windows Azure credits I received as part of my MSDN Subscription, and let me tell you… Microsoft is certainly on the right track. While I’ll go into the details of how pleased I am with the service another time, I’d like to focus on the concept of SVN commit hooks and how you can use them to leverage the wonderous glory that is Windows PowerShell.
I’m using VisualSVN Server for this proof-of-concept environment, which is a pretty standard and easy-to-use SVN server platform. Alongside Jenkins, an automated build platform, I hope to create a platform on Azure that we can use to quickly adapt to given situations; i.e. QA Test ramps up 2 servers to test the latest release, Developer ramps up 2 clients and a server for new feature development, maybe these servers are stood up at each release with the latest and greatest… but I digress for now I am daydreaming
So, right-clicking a repo in the VisualSVN management console and going to Properties, I’m presented with a series of “hooks”. These are spots where I can drop an executable that will be triggered upon whichever event I assign it in:
Now the first thing I want to do on the SVN server is to build out a directory where all of my hook executables can live and trigger PowerShell from. I chose C:\DATA\AutoBuild\, as I plan to use the term ‘AutoBuild’ to reference this PS behavior wherever I use it. I place two files in there, ‘PreCommitHook.cmd’ and ‘PostCommitHook.cmd’. You can guess what they’ll do, I’ll put some simple echoing in them for now to test functionality. Once they’re confirmed okay I will also add ‘PreCommit.ps1′ and ‘PostCommit.ps1′ as targets for the cmd files to execute in PowerShell. I’ll also make sure to receive the two arguments coming in from a VisualSVN hook call, which are repo path and revision #. My first hack at PostCommitHook.cmd looks like this:
echo Initiating Post-Commit Hook
echo Repository Path: %1
echo Revision Number: %2
Just takes in the 2 arguments and spits them back out, not too exciting. Until I add the hook into PowerShell, as now the script becomes available for use. I put this immediately after the batch code above:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -c “. \”C:\DATA\AutoBuild\PostCommit.ps1\”"
Inside PostCommit.ps1, a simple indicator that we got in there okay and we’re doing alright:
# Just make sure we got in here okay
Get-Command *file* | Out-Default
All that being said, time to run the PostCommitHook.cmd to see where we stand:
YES, PowerShell output from our post-commit hook! That’s it for now, I’ll do a part 2 when time allows and link it here about going further with this hook functionality and the opportunities that arise as a result.