【问题标题】:how to add the pre-receive hook in server side in GitLab?如何在 GitLab 的服务器端添加预接收挂钩?
【发布时间】:2017-08-29 06:16:46
【问题描述】:

我正在尝试限制在我们的 gitlab 中提交的二进制文件(EXE、DLL、PDF)。所以我需要添加钩子以在全局范围内限制它。我怎样才能做到这一点? Pre-receive hook 适合这个吗?

这个地方加钩子对吗?

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

任何帮助表示赞赏!

【问题讨论】:

标签: git gitlab githooks


【解决方案1】:

正如我评论的那样,对于每个项目,请使用 custom hooks: (Chained hooks support)
请参阅“How can I add hooks to gitlab?”中的确切步骤,并涉及创建专用repo.git/custom_hooks 子文件夹。

但这是针对每个存储库的,并非针对所有存储库。
您需要为组的每个 repo 添加该脚本。

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

【讨论】:

  • 你的意思是,我需要在服务器机器的每个 repo 中添加 pre-receive 钩子?
  • @Arunkumar 是的,或者如果你愿意,至少是一个通用脚本的符号链接。
【解决方案2】:

您可以安装一个侧宽挂钩,但它没有很好的文档记录。 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

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 2018-11-03
    • 2020-02-11
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    相关资源
    最近更新 更多