i having a bat-file with name jenkins.bat to start building process on a jenkins server.
Now I want to execute this bat-file as post-commit-hook in git.
Therefore a created following file post-commit in the folder /.git/hooks:
#!/bin/bash
/.git/hooks/jenkins.bat
But eclipse throws me every time an exception when commiting code changes to git! Did I miss something?
You need to use either an absolute or relative path
absolute: /c/...
or, as commented, relative, meaning not starting with a /
./jenkins.bat
Assuming your post-commit hook is executable, and in the <repo>/.git/hooks folder, where your jenkins.bat appears to be.
As Paul mentions in the comments
Doing ./jenkins.bat does not work when the batch file is in the hooks directory: you will get a "no such file" error.
This is because of the hook's working dir.
Related
Because of its simplicity, we use remote repository placed on shared disk, accessing it using file system path (\server\share). Is is possible, in such case, to run hook scripts defined in remote repository? I have defined one but it seems like it is not launched (tested using non valid edit in hook script, witch should cause an error).
Git hook is a script you can run before (pre-commit) or after (post-commit) a commit is made. There can be more than one of such a script.
They are placed in a specified folder. Any git repository has a .git/hooks folder with file(s) containing hook scripts.
You need to answer
Do you have the event you are testing bind to a hook present in your's git repository?
Check also this on how git executes hooks in Windows:
Executing Git hooks on Windows
Git Hook under Windows
Tips for using hooks:
https://codeinthehole.com/tips/tips-for-using-a-git-pre-commit-hook/
https://omerkatz.com/blog/2013/2/15/git-hooks-part-1-the-basics
http://longair.net/blog/2011/04/09/missing-git-hooks-documentation/
Some more git hooks reading:
http://git-scm.com/book/en/Customizing-Git-Git-Hooks
http://githooks.com/
My advice after few hours of fight, double check value:
git config core.hookspath
It should be empty or point your hooks folder (.git\hooks)
If you run the command:
git config core.hooksPath .git-hooks
This will look for the hooks in the folder .git-hooks from your project root, same as where you find .git folder. When the commands are run in this folder, take note that the directory being executed from then is the project root - and not in the .git-hooks folder having the actual hooks. This is why you get the "command not found".
Example contents of .git-hooks/post-merge file
!#!/bin/bash
bower install
The "bower install" command is run from the parent directory.
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.
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.
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.
I'm trying to get a git post-receive hook working on Windows.
I'm using Git 1.7.9 (Msysgit) and have a repo locally and a bare repo on a remote server. I can fetch, commit, push etc. I've set up a post-receive hook that should checkout the files into a working folder (part of the deployment process) but it doesn't seem to work.
Here's what I do:
Change a file, stage and commit it
Push to remote server - successfully
Expect to see the echo - don't see the echo
Check working folder on server - latest files are not there
Log onto the server and run the hook script manually - latest files are checkout out into the working folder.
I changed the hook so it does nothing except echo a message and I've read that I should see this in my console after pushing. But this is not being displayed so I can only assume the hook is not being fired off.
I'm pushing over HTTP with git dot aspx on the server handling the request and pusing via the gui locally. After that failed I tried Bonobo and the hook doesn't work when pushing via the gui or a bash console.
I'm assuming someone has this working somewhere but after two days of searching all I have found are solutions that don't help or people with the same problem that has gone unanswered.
(I'm a git newbie btw).
Cheers.
Update
I'm starting to think it may be to do with permissions - but Unix permissions, rather than NTFS. When #eis mentioned permissions I had assumed NTFS. But after more digging it seems that Git on Windows still checks for Unix file perms.
So I suspect the issue is that the post-receive file is not executable as when I do a ls -o it's -rw-r--r-- (644 I believe). If I try and change this through bash and chmod 777 post-receive then do ls -o the permissions are the same.
The strange this is that as soon as I edited post-receive (with notepad++) the execute bit gets removed. (my test script that ends in .bat does retain its execute bits though...)
BTW, the user I'm logged on as is the owner of the files (according to ls -o) and yet I can't set the permissions.
Starting to get really confused now. Am I missing something really obvious?
Update 2
Neither chmod 777 post-receive nor chmod a+x post-receive work. I took a new, clean post-receive file, uploaded it the to the server and checked the permissions and it had execute. If I rename the file (to remove sample) in Windows then execute is removed. If I do it in bash with mv execute is retained.
But, whenever I edit the file (in Windows or in bash with vi) then execute gets removed.
So, the problem now is why does it remove the execute bits when I edit the file?
Hopefully this is the final hurdle and the cause of it not executing...
You are going to have to patch git to make this work. The checks in builtin/receive-pack.c are for access(path, X_OK). In msysgit this diverts to mingw_access which throws away the X_OK bit as it is simple not supported on Windows.
On windows, we have no flag to specify a file is executable. Systems often do some emulation of this. For instance, tcl will look for any extension in the PATHEXT environment variable to decide that a file is executable. We can't do that here as the hook names are hardcoded without any extensions.
Instead, I suggest changing the access test to just check the file exists and then call execv on the path. The mingw version of this (in compat/mingw.c) looks for script files and will read the shbang line and launch an appropriate interpreter (sh, perl etc). So modifying builtin/receive-pack.c:run_update_hook should let this work for you. Currently the hook running uses start_command and I think that should call down to execv for you.
In short, change the access test and it will probably work.
When using msysgit on the server and pushing via a file share hooks work without problem now. Maybe this was fixed in mysysgit since the answer was written. I didn't look into it.
I also noticed that the original question stated git dot aspx and Bonobo were being used which use GitSharp.dll. This would mean the application is not shelling out to the git.exe and hooks would not be handled the same way.
For example, the GitSharp.dll used in git dot aspx has it's own hook post-receive hook implementation which could be performed in C#:
public void Receive(Stream inputStream, Stream outputStream)
{
using (var repository = GetRepository())
{
var pack = new ReceivePack(repository);
pack.setBiDirectionalPipe(false);
//setup post receive hook here
pack.setPostReceiveHook(new PostRecieveHook());
pack.receive(inputStream, outputStream, outputStream);
}
}
public class PostRecieveHook : IPostReceiveHook
{
public void OnPostReceive(ReceivePack rp, ICollection<ReceiveCommand> commands)
{
//Do PostRecieve Hook Work Here
}
}
I hope to help others with confusion between libraries that are implementations of Git and applications that call out to the actual git.exe.