How do I create a GitLab webhook?

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:28:11

问题


I've read that GitLab is capable of sending messages to other servers via "web hooks" but I can't find where one would create one.

Can someone point me in the right direction?


回答1:


All the answers I've found in official documentation and on Stack Overflow for finding web hooks are incorrect. The admin area > hooks page does NOT contain web hooks. It contains system hooks, which fire when you create/delete projects and users and things like that. This is not what you want.

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 RequestBin to see what the payload looks like and to ensure you're firing these off correctly for debugging purposes.




回答2:


With version 8.16.1, I found the web hooks under

specific project > settings > integrations




回答3:


For group level hooks:

visit: https://gitlab.com/groups/<yourgroup>/hooks

For group project level hooks:

visit: https://gitlab.com/yourgroup/yourproject/hooks




回答4:


You can see an example of GitLab system hook, with a web_hook.rb creation in this GitHub project.

In gitlab, as admin, go to "Hooks" tab, create hook as: http://your.ip.goes.here:8000

or change the port on line 175 of the script.

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.

Be aware though that a few issues remain with gitlab webhook:

  • it is not always firing
  • There's no URL nor namespace key present on system's webhook



回答5:


I recommend using GitLabForm - configuration as code tool for GitLab - to configure webhooks with code like this:

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.



来源:https://stackoverflow.com/questions/17157969/how-do-i-create-a-gitlab-webhook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!