git - 使用 gitlab 自定义接收后 Hook

标签 git gitlab webhooks

我正在尝试使用 gitlab 设置自定义的接收后 Hook

我正在关注他们的文档 here

我在 custom_hooks 文件夹中有一个可执行的接收后文件,其中包含以下代码:

 !/bin/bash
 echo "post-receive firing | wall
 git pull

如果我运行这个文件:

 ./post-receive

它工作正常。当推送到 gitlab 存储库时,它似乎根本没有触发。

这是我第一次尝试任何类型的网络钩子(Hook),所以我有点迷茫。

a) 我的远程网络服务器上有上述脚本,在 .git/custom_hooks 文件夹内,是否正确?

b) 我需要在 repo 中做任何事情吗?

c) 在文档中,它指定我应该设置文件的权限,以便它归“git”用户所有。我在网络服务器上没有 git 用户...所有其他与 git 相关的文件都归我的用户或 root 所有。

因此,假设我在这里做错了一些事情,有人可以让我摆脱痛苦,并建议一种理智的方法来在我从本地计算机推送到 gitlab 时自动推送到 Web 服务器。我觉得我已经花了一些时间寻找一种方法来做到这一点,而解决方案似乎完全矫枉过正(cronjob 每隔几秒运行一次......)或者像上面那样,似乎不起作用。或者至少我似乎无法让它们发挥作用。

当然这是一项简单的任务...

最佳答案

on the file so it is owned by the 'git' user. I have no git user on the webserver... all other git related files are owned by my user or root.

那是因为你的网络服务器是 GitLab 服务器的客户端。
documentation you reference用于配置 GitLab 服务器(向 GitLab 存储库添加接收后 Hook )。 Hence the 'git' user, which is the default one on a GitLab server .

但是如果你要推送到 gitlab.com,你不会直接添加一个钩子(Hook)。

您需要声明一个 web hook ,然后它会发回一条 JSON 消息,您 can listen to in order to trigger another action .

如果只有你一个人推送,you could simply push to multiple repos .那里没有钩子(Hook),客户端或服务器。
但那将是仅对您本地克隆的存储库有效的本地设置。

关于git - 使用 gitlab 自定义接收后 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30839669/

相关文章:

git - 在 IntelliJ 项目中更改在线 git 存储库 url

node.js - 如何使用 stripe webhooks 更新用户的订阅日期?

c# - 使用 C# 下载 Twilio 录音

ruby-on-rails - 用于 rails 4 的 Stripe webhooks

git - .gitignore 并没有忽略自己

node.js - npm install 时发生致命坏对象错误

Gitlab : Peer's certificate issuer has been marked as not trusted by the user

python - GitLab API - 如何获取存储库/项目文件和元数据?

windows - Jenkins Windows Slave 忽略本地 Git 设置

git - 从 git 存储库中删除无关的提交