如何在GitLab服务器端添加pre-receive hook?

3

我想限制在我们的gitlab中提交二进制文件(EXE,DLL,PDF)。因此,我需要添加挂钩以在全局范围内进行限制。我该如何做?Pre-receive hook是否适合此操作?

这里是添加挂钩的正确位置吗?

/opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive

非常感谢任何帮助!


2
对于每个项目,请使用自定义钩子:https://dev59.com/sGAf5IYBdhLWcg3w52Ll#24155063(https://docs.gitlab.com/ce/administration/custom_hooks.html#chained-hooks-support) - VonC
@VonC 但我不知道如何使用它。你能简要解释一下吗? - user6874415
我下班后会做。 - VonC
我也想将这个添加为全局。 - user6874415
期待您的回复,谢谢。 - user6874415
2个回答

0

您可以安装全站钩子,但文档不是很完善。Gitlab目前正在集成gitlab-shellgitaly。因此,提供说明有点像移动目标,但它们在12.3.5版本发布时是有效的。

gitlab-shell/hooks/*中的脚本会扫描当前存储库和全站目录。但是,在干净的安装中不会创建全站目录,您需要自己创建。

mkdir -p <XXX>/gitlab-shell/hooks/pre-receive.d       # or update.d or post-receive.d
chown git:git <XXX>/gitlab-shell/hooks/pre-receive.d

# link or copy your script of course it needs to be executable by the Gitlab user
ln -s /usr/bin/my-hook <XXX>/gitlab-shell/hooks/pre-receive.d/my-hook

0

如我所评论的,对于每个项目,请使用 自定义钩子:(链式钩子支持)
请在 "如何向GitLab添加钩子" 查看详细步骤,并涉及创建一个专用的 repo.git/custom_hooks 子文件夹。

但这是针对每个存储库而不是所有存储库。
您需要为组中的每个存储库添加该脚本。

您在普通 repo.git/hooks 文件夹中看到的 pre-receive 脚本实际上是指向 gitlab-shell hook 文件夹的符号链接,并且 GitLab 使用它来管理访问权限。


你的意思是,我需要在服务器机器上的每个仓库中添加pre-receive hook吗? - user6874415
@Arunkumar 是的,或者如果你想要的话,至少可以创建一个指向一个公共脚本的符号链接。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接