git挂钩以及它们如何工作 [英] git hooks and how they work

查看:131
本文介绍了git挂钩以及它们如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图让哈德森建立一个后接收钩。在我的本地git repo中,我将post-receive.sample设置为只接收后,chmod 755,并添加到行中:

  / usr / bin / curl -u user:secret http:// localhost:8080 / hudson / job / MyJob / build?token = secondsecret 

如果我强制构建,哈德森更新代码,但这里是我不明白,该回购的钩子没有后面的.sample,就像他们在本地做的一样,在哈德森回购后收到没有上面的代码行。这里发生了什么,以及钩子如何整合到整个git过程中?我是否需要更改远程回购的钩子?我本来认为这足以在本地完成,并推动任何从该回购中获取的人获得新的挂钩。我无法理解另一个用户的repo会有不同的钩子。

解决方案

您基本上有两种选择: b
$ b


  1. post-receive 钩子放置在服务器上并让服务器运行curl。

  2. 在本地仓库中放置一个后提交钩子并让本地盒子运行。

由于您的构建作业可能会从服务器上的回购库中构建代码,因此只有选项1有意义。在情况2中,构建作业可能需要从本地框中获取代码,这可能不是你想要的。



你不能将挂钩放到 server 使用 git push 。您(或具有适当权限的人)需要手动登录到服务器并在本地修改钩子脚本文件。


So I'm trying to get hudson to build with a post-receive hook. In my local git repo I set post-receive.sample to just post-receive, chmod 755 and added in the line:

/usr/bin/curl -u user:secret http://localhost:8080/hudson/job/MyJob/build?token=secondsecret

If I force a build, hudson updates the code, but here's what I don't understand, the hooks in that repo DON't have the .sample after them like they do locally, and the post-receive in the hudson repo doesn't have that line of code above. What's going on here and how are hooks integrated into the whole git process? Do I need to be changing this hook on the remote repo? I would have thought it was enough to do it locally and push so anyone fetching from that repo get the new hooks. I can't understand how another user's repo would have different hooks.

解决方案

You basically have two options:

  1. Place the post-receive hook on the server and let the server run curl.
  2. Place a post-commit hook on your local repo and let your local box run curl.

As your build job will probably fetch the code to build from the repo on the server, only option 1. makes sense. In case 2., the build job would probably have to fetch the code from your local box, and that is probably not what you want.

You cannot place hooks onto the server using git push. You (or someone with the appropriate permissions) needs to do that by manually logging into server and modifying the hook script files locally.

这篇关于git挂钩以及它们如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆