git 如何创建 GitLab 网络钩子?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17157969/
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
How do I create a GitLab webhook?
提问by leech
I've read that GitLab is capable of sending messages to other servers via "web hooks" but I can't find whereone would create one.
我读过 GitLab 能够通过“网络钩子”向其他服务器发送消息,但我找不到在哪里创建一个。
Can someone point me in the right direction?
有人可以指出我正确的方向吗?
回答by Jamey
All the answers I've found in official documentation and on Stack Overflow for finding web hooksare incorrect. The admin area > hooks
page does NOT contain webhooks. It contains systemhooks, which fire when you create/delete projects and users and things like that. This is not what you want.
我在官方文档和 Stack Overflow 上找到的用于查找Web 钩子的所有答案都不正确。该admin area > hooks
页面不包含网络钩子。它包含系统钩子,当你创建/删除项目和用户以及类似的东西时会触发。这不是你想要的。
To find your web hooks, go to the specific project > settings > web hooks (on sidebar in GitLab 6.1.0)
page. These will fire on post-receive for the project in question. You can use a service like RequestBinto see what the payload looks like and to ensure you're firing these off correctly for debugging purposes.
要找到您的网络挂钩,请转到该specific project > settings > web hooks (on sidebar in GitLab 6.1.0)
页面。这些将在相关项目的接收后触发。您可以使用RequestBin 之类的服务来查看有效负载的外观,并确保出于调试目的正确触发这些负载。
回答by derwiwie
回答by Blair Anderson
For group level hooks:
对于组级挂钩:
visit: https://gitlab.com/groups/<yourgroup>/hooks
访问: https://gitlab.com/groups/<yourgroup>/hooks
For group project level hooks:
对于组项目级挂钩:
visit: https://gitlab.com/yourgroup/yourproject/hooks
访问: https://gitlab.com/yourgroup/yourproject/hooks
回答by VonC
You can see an example of GitLab system hook, with a web_hook.rbcreation in this GitHub project.
你可以看到一个 GitLab 系统钩子的例子,在这个GitHub 项目中创建了一个web_hook.rb。
In gitlab, as admin, go to "
Hooks
" tab, create hook as: http://your.ip.goes.here:8000or change the port on line 175 of the script.
在gitlab,作为管理员,进入“
Hooks
”选项卡中,创建挂钩为:http://your.ip.goes.here:8000或更改脚本第 175 行的端口。
For web hooks, see Jamey's more accurate answer.
You can inspect the result of a webhook with a service like RequestBin.
Another example of webhook interpretation: this question.
您可以使用RequestBin 之类的服务检查 webhook 的结果。
webhook 解释的另一个例子:这个问题。
Be aware though that a few issues remain with gitlab webhook:
请注意,gitlab webhook 仍然存在一些问题:
回答by Greg Dubicki
I recommend using GitLabForm- configuration as code tool for GitLab - to configure webhooks with code like this:
我建议使用GitLabForm- 配置作为 GitLab 的代码工具 - 使用如下代码配置 webhooks:
project_settings:
my_group/my_project:
hooks:
hooks:
'http://127.0.0.1:5000/hooks/my-hook-endpoint':
push_events: false # this is set to true by GitLab API by default
merge_requests_events: true
token: some_secret_auth_token
Disclosure:I wrote this tool and my company open-sourced it.
披露:我编写了这个工具,我的公司将其开源。