SVN Post Commit Hook Batch Windows - windows

I have a Windows Server running Visual SVN Server to store our repositories.
Also on that server is our test copy.
I'm trying to set up a simple SVN post-commit hook so it updates that test copy automatically every time I commit something
In Visual SVN in the post-commit hooks I've set up like this
"C:\Program Files (x86)\VisualSVN Server\bin\updatescripts.bat" D:\inetpub\TESTCOPY
Then that batch file has a simple update like this
PATH=%PATH%;"C:\Program Files (x86)\VisualSVN Server\bin\"
svn update %1
If I run the batch file in the server by double clicking on it or from command line works fine.
When committing something from my laptop it freezes and doesn't give me any error and locks the test copy so then I need to go in and run a clean up.
Visual SVN service is running as network service and this aacount has full access to the bin folder and the test copy on the server.
Any idea how to set up a simple svn update post commit hook anyone?
Thanks
Fede

I had a similar problem and it turned out to be that SVN likes paths to use forward slashes instead of backslashes.
Try this:
set MYPATH=%1
:: Transform backslashes to forward slashes
set MYPATH=%MYPATH:^\=/%
svn update %MYPATH%

You're running the svn update command. Exactly what working copy are you trying to update?
The parameter being passed is the Repository's path. This points not to a working directory, but to the directory that contains the Subversion master repository. This is the same directory where your post commit hook is stored.
Subversion hooks do not have access to the user's working directory, so you can't manipulate the user's files. Hook scripts usually should be using svnlook and not svn. By doing this, you prevent yourself from getting into any sort of trouble.
It is possible to update a Subversion working copy on the server, if you know the location:
PATH=%PATH%;"C:\Program Files (x86)\VisualSVN Server\bin\"
set SVN_WORK_DIR=C:\SVN\workdir"
svn update %SVN_WORK_DIR%
However, I wouldn't recommend this because it ties up Subversion. The user who did the commit would have to wait until the update is complete before Subversion returns the control of the prompt back to the user.

After trying a million different things this worked for me...
I put this in my post-commit hook
"C:\Program Files\VisualSVN Server\bin\svn.exe" update "C:\my path\"
where my path is the path to the working copy to be updated
Also I had to change the service to run as local system

That is really not the way you want to do that. What you should do is use something like Jenkins to watch your repository. Jenkins can watch your repository, and it when it changes, update your test copy, kick-off builds, run automated tests, etc.

Related

Bonobo Git Server: how do you open complete repository in windows explorer/backup?

I recently installed Bonobo git server on my workstation. It will work as a git server for me and my colleagues. Using a script, the repositories will be stored on a separate server usinng a .bat file to copy the files regularly. The problem is I don't know where to find the repo files. I selected D:/git_repo as destination for bonobo repositories, but when i go there in explorer, there are only a few files and not the sources (the folders are alos only a few hundreads kbs big).
Do you have any ideea where the complete files are located?
If it was me, instead of using a scheduled script to copy the repository files to a separate server, I would on the destination/backup server have a scheduled task that performed a 'git pull' from your server.
Did you changed the Repository directory in the Bonobo UI settings ?
If you did, try to restart the IIS service.
If none helps, thenWhat exactly are you copying ? If your repositories are initialy exist, either by a script you execute or by the Bonobo UI, they can be created directly to your D:\Git_Repos as you specify

Subversion post-commit hook will not run on commit, script works because I can run it on the command line

I have just made a new repository. My server is Ubuntu 12.04 32 bit.
I want my commits to be live as soon as I have committed them. This is achieved by making a working copy in my public html directory, and having the post-commit hook update that working copy. I have set that up using the instructions here:
http://www.frenssen.be/content/using-subversion-automatically-update-live-website
The issue is that my post-commit will not run when my project commits. My project commits just fine. I know that the script is a valid script too, because I can run it with
env ./post-commit
inside of the hooks directory and it properly updates.
I thought it might be a permissions thing so I have made extensive use of chown to ensure that www-data is the owner of:
the repo /home/svn/repo2
the working copy /var/www/html
the hook /home/svn/repo2/hooks/post-commit
the update binary /home/svn/autoupdate/autoupdate
But still nothing. My commits are successful, but the hook never runs. My hook script looks like this:
#!/bin/sh
/home/svn/autoupdate/autoupdate
All of the googling seems to be pointing to a permissions issue but I can't figure this one out.
Can you repeat this guy's example, and see if it works at all?
mikewest.org/2006/06/subversion-post-commit-hooks-101
Do you get an error when you commit?
If your post-commit hook actually failed, I think you would see evidence of that in whatever client you were using to perform the checkin. I'm almost suspecting that post-commit is not firing at all. Just to double check, the file needs to actually be called post-commit, all lowercase, and not post-commit.tmpl.

Jekyll private deployment?

I have created jekyll site. Regarding the deployment I don't want to host on github pages. To host private domain I came know from documentation to copy the all files from _site folder. That's all wicked.
Question:
Each time I add new blog post, I am running cmd>jekyll build then I am copying newly created html to hosted domain. Is there any easy way to update without compiling each time ?
The reason, Why I am asking is because it will updated by non technical person
Thanks for the help!!
If you don't want to use GitHub Pages, AFAIK there's no other way than to compile your site each time you make a change.
But of course you can script/automate as much as possible.
That's what I do with my own blog as well. I'm hosting it on my own webspace instead of GitHub Pages, so I need to do these steps for each update:
Compile on local machine
Upload via FTP
I can do this with a single click (okay, a single double-click).
Note: I'm on Windows, so the following solution is for Windows.
But if you're using Linux/MacOS/whatever, of course you can use the tools given there to build something similar.
I'm using a batch file (the Windows equivalent to a shell script) to compile my site and then call WinSCP, a free command-line FTP client.
WinSCP allows me to store session configurations, so I saved the connection to my server there once.
Because of this, I didn't want to commit WinSCP to my (public) repository, so my script expects WinSCP in the parent folder.
The batch file looks like this:
call jekyll build
echo If the build succeeded, press RETURN to upload!
pause
set uploadpath=%~dp0\_site
%~dp0\..\winscp.com /script=build-upload.txt /xmllog=build-upload.log
pause
The first parameter in the WinSCP call (/script=build-upload.txt) specifies the script file which contains the actual WinSCP commands
This is in the script file:
option batch abort
option confirm off
open blog
synchronize remote -delete "%uploadpath%"
close
exit
Some explanations:
%~dp0 (in the batch file) is the folder where the current batch file is
The set uploadpath=... line (in the batch file) saves the complete path to the generated site into an environment variable
The open blog line (in the script file) opens a connection to the pre-saved session configuration (which I named blog)
The synchronize remote ... line (in the script file) uses the synchronize command to sync from the local folder (saved in %uploadpath%, the environment variable from step 2) to the server.
IMO this solution is suitable for non-technical persons as well.
If the technical person in your case doesn't know how to use source control, you could even script committing & pushing, too.
There are a number of options available which are mentioned in the documentation: http://jekyllrb.com/docs/deployment-methods/
If you are using Git, I would recommend the Git Post-Receive Hook approach. It simply builds the site after the new code is received:
GIT_REPO=$HOME/myrepo.git
TMP_GIT_CLONE=$HOME/tmp/myrepo
PUBLIC_WWW=/var/www/myrepo
git clone $GIT_REPO $TMP_GIT_CLONE
jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
Since you mentioned that it will be updated by a non-technical person, you might try something like rack-jekyll to automatically rebuild when new files are FTP'd.

Global Subversion SSH config in Windows / Checking out Subversion project as SYSTEM on Windows

I'm trying to set up a scheduled Subversion commit from Windows Server 2003 machine over SVN+SSH as a task. I'd like the commit script to be executed as SYSTEM-user. So I'm guessing, for that to work I need to check-out the repository as SYSTEM, too - but am unable to achieve it so far.
I'm already able to achieve the above with my own user over SSH. I've done the following:
I added a [tunnels] entity in my local subversion configuration:
ssh = plink.exe -i "C:/Keys/my_key.ppk"
Added the key to the authorized_keys file on the server running Subversion
I checked out the repository with a script as below:
svn co svn+ssh://user#server/path/to/repo/ C:\Local\Project\Path
I'd now like to reproduce the above steps for SYSTEM user, to be able to run a scheduled commit later. The problem I'm facing is I don't know how to check out the repository as SYSTEM, because:
I don't know the syntax to use to check out a repository as SYSTEM
I don't know where the global (or SYSTEM's) Subversion config is stored on a Windows Server 2003. I've already tried: C:\Documents and Settings\Default User\Application Data\Subversion and C:\Documents and Settings\Administrator\Application Data\Subversion, but without success.
I also read somewhere I possibly could use svn switch for what I want, but wouldn't know how to svn switch as SYSTEM. I also considered writing scripts for svn check-out or switch and running them as SYSTEM, but then I still need global SVN config to add my_key.ppk, too.
I hope the above description is clear enough. I've been struggling with it for a long time now and am having problems summarizing it myself. Any hints appreciated.
As a side, that doesn't seem to be totally off-topic: https://serverfault.com/q/9325/122307
This is not a real answer to your question, yet it might solve your problem: Why not use svn <command> --config-dir ARG or svn <command> --config-option ARG?
You could specify the config file/option like this, thus being able to set [tunnels].
#cxxl really answered on question, when mentioned --config-dir. I'll just try to shed some light on problem
I'm guessing, for that to work I need to check-out the repository as SYSTEM
Wrong and bad guessing, because stored locally user's auth data doesn't used in case of SSH-auth, for ssh remote authentication performed. Per-user auth-dir
\%AppData%\Subversion\auth>dir /W
...
[svn.simple] [svn.ssl.client-passphrase]
[svn.ssl.server] [svn.username]
...
contain stored credentials only for http|https|svn and cert-based client authentication, and nothing for ssh-related repositories
I.e your executed under LSA script must be able to
* read Working Copy files (checkouted under any other real local user), maybe write (can't recall requirement for .svn dir permissions)
* read and, thus, use predefined and fine-tuned Subversion's config files (tunnel section), which can be config of any other user
PS: swn switch change linked URL of repository for Working Copy and have nothing common with users

Anyone got a sample Windows batch file for auto-deploying Collabnet repo to a file folder?

I'm using CollabNet Subversion Edge on Windows 2008 … and trying to auto-deploy (so update from repo to folder) when any commits are made by developers using Tortoise SVN.
I've got a post-commit hook file in the correct repo /hooks folder. The file is named post-commit.bat
The file has one line -
"C:\Program Files\TortoiseSVN\bin\tortoiseproc.exe" /command:update /path:"c:\wamp\www\thewebsite*" /closeonend:1 /outfile:"c:\csvn\update-logs\thewebsite-out.txt"
When I commit anything, it's timing out if I have the file present. If the file is not present, the commits work without any problem. So that tells me the post-commit file is being called … and it's got a problem!
Anyone got a sample post-commit Windows batch file that can help me? Or know how to solve my particular problem?
You should try testing your script by simply calling it from the command line and passing in the repo and version parameters. This might give you some more insight as to why it is timing out. For example:
script.bat PATH_TO_REPO REPO_VERSION
Also instead of using Tortoise, use the native SVN client library. In your script you can navigate to the folder you want to update, and call the "svn update" command. This will be more straightforward and not have to go through Tortoise just to make the update command back to the native library.
Try something like this:
cd "c:\wamp\www\thewebsite"
svn update
If your SVN server requires permissions you may need to pass these in your script as well.

Resources