Git post-receive hook 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4950800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git post-receive hook not working
提问by spanky
My setup is a windows XAMPP server, with cURL enabled, and Git and Hudson installed. Hudson polls Git every minute to look for changes, and if it finds them, it creates a build. I use this build as my testing server. This works fine.
我的设置是一个 Windows XAMPP 服务器,启用了 cURL,并安装了 Git 和 Hudson。Hudson 每分钟轮询 Git 以查找更改,如果找到更改,则创建一个构建。我使用这个版本作为我的测试服务器。这工作正常。
I would like to set up a post-receive hook on my central remote repository that runs the force build function of Hudson.
我想在我的中央远程存储库上设置一个 post-receive hook,它运行 Hudson 的强制构建功能。
I've created a post-receive file called "post-receive" in the hooks directory in my central Git repository, the one that is pushed to from the developers' local branches. They each push to their own branch on the central repository. I want to run the post-receive build immediately after every push, instead of having Hudson poll Git every minute.
我在中央 Git 存储库的 hooks 目录中创建了一个名为“post-receive”的接收后文件,该文件是从开发人员的本地分支推送到的。他们每个人都推送到中央存储库上自己的分支。我想在每次推送后立即运行接收后构建,而不是让 Hudson 每分钟轮询一次 Git。
When I open a shell to the remote server and run "post-receive" in the hooks folder, it runs. It just isn't being called when people push to it from their local repository copies to the central one.
当我打开远程服务器的 shell 并在 hooks 文件夹中运行“post-receive”时,它会运行。当人们从他们的本地存储库副本推送到中央存储库副本时,它不会被调用。
Maybe I'm not explaining this right, but it's how I understand Git.
也许我没有正确解释这一点,但这就是我理解 Git 的方式。
The post-receive code is two lines:
接收后的代码是两行:
#!/bin/sh
curl http://myserver.com:8080/hudson/job/myjobname/build?token=mytoken
Again, when I open a shell and run this, it works, but when someone pushes to it, nothing happens, until a minute or less goes by, Hudson realizes that Git was changed, and then it builds.
同样,当我打开一个 shell 并运行它时,它可以工作,但是当有人推送它时,什么也没有发生,直到一分钟或更短的时间过去,Hudson 意识到 Git 被更改了,然后它会构建。
I am happy to clarify if need be. Any help is greatly appreciated.
如果需要,我很乐意澄清。任何帮助是极大的赞赏。
EDIT: After playing around with it, I feel like maybe post-receive isn't executing because refs aren't being updated of something? The git documentation says
编辑:在玩弄它之后,我觉得可能 post-receive 没有执行,因为 refs 没有更新某些东西?git 文档说
It executes on the remote repository once after all the refs have been updated.
在更新所有引用后,它会在远程存储库上执行一次。
Does this mean if nothing updates, it won't execute? And if so, I'm pretty sure things are updating anyway so it shouldn't apply.
这是否意味着如果没有任何更新,它就不会执行?如果是这样,我很确定事情无论如何都会更新,所以它不应该适用。
Here's my process: Make edits locally. Commit edits. Push from my HEAD to the remote branch called 'mybranch' (not the master branch, which is checked out) This is the point at which I want my hook to execute.
这是我的过程:在本地进行编辑。提交编辑。从我的 HEAD 推送到名为“mybranch”的远程分支(不是已检出的主分支)这是我希望钩子执行的点。
采纳答案by spanky
All of these answers are useful, but it turns out I needed the "bin" directory of git in my PATH variable. I had the "cmd" directory only. Added c:\my_path_to_git\git\bin
to PATH and it works fine. I found this answer by trial and error and looking at the apache error log. Thank you all for your help!
所有这些答案都很有用,但结果证明我的 PATH 变量中需要 git 的“bin”目录。我只有“cmd”目录。添加c:\my_path_to_git\git\bin
到 PATH 并且它工作正常。我通过反复试验和查看 apache 错误日志找到了这个答案。谢谢大家的帮助!
回答by msquared
Please check whether your file has executable rights. Otherwise it can not be executed.
Something like rwxr-xr-x
should be sufficient.
请检查您的文件是否具有可执行权限。否则无法执行。类似的东西rwxr-xr-x
应该就足够了。
You can add the missing bit with
您可以添加缺少的位
$ chmod +x /path/to/post-receive
回答by Arrowmaster
What transport method are you using to push to the repo?
您使用什么传输方法推送到 repo?
Hooks are only executed when using 'smart' transport protocols like ssh and the cgi implementation of http. For other 'dumb' transport protocols like ftp, rsync, and the older http implementation, hooks will never be executed. I assume the git protocol would execute hooks but pushing over that protocol has never been considered a good idea.
挂钩仅在使用“智能”传输协议(如 ssh 和 http 的 cgi 实现)时执行。对于其他“哑”传输协议,如 ftp、rsync 和较旧的 http 实现,永远不会执行钩子。我认为 git 协议会执行钩子,但推动该协议从来都不是一个好主意。
回答by Mark Livingston
I think the simple answer is you need to move the contents of the post-receive hook server side instead of client side
我认为简单的答案是您需要移动 post-receive hook 服务器端而不是客户端的内容
回答by XANi
Try using full path to curl in post-receive file, as PATH can be different than when running script by hand.
尝试在接收后文件中使用完整路径 curl ,因为 PATH 可能与手动运行脚本时不同。
If you want to see what is the environment of running post-receive script:
如果你想看看运行 post-receive 脚本的环境是什么:
#!/bin/sh
export > file
or just (it will show env. variables after pushing into repo)
或者只是(它会在推入 repo 后显示环境变量)
#!/bin/sh
export
Also, I'm not sure how executing shell scrips works on windows, so #!/path/to/installed/sh instead of #!/bin/sh might help
另外,我不确定如何在 Windows 上执行 shell 脚本,所以 #!/path/to/installed/sh 而不是 #!/bin/sh 可能会有所帮助