gpt4 book ai didi

git - 如何将钩子(Hook)添加到 gitlab?

转载 作者:IT王子 更新时间:2023-10-29 00:37:39 26 4
gpt4 key购买 nike

我在 /opt/gitlab-6.9.2-0/apps/gitlab/ 上的 CentOs 上设置了一个新的 Gitlab,并在持续交付组下创建了一个新的存储库。完整路径是 /opt/gitlab-6.9.2-0/apps/gitlab/gitlab-satellites/continuous-delivery/cd-test
。该路径下只有一个文件README.txt。

我试图实现的是在有人将更改推送到服务器时创建一个新文件。以下是我在服务器上所做的:

  1. .git/hooks/下创建 post-updateupdate 文件' 每个文件使用 echo "text"> 创建一个新文件> 文件名`
  2. 将它们修改为 775。

当我将更改从本地推送到服务器时,没有创建任何文件。所以,我想知道我必须做些什么来解决这个问题。

更新 1

我将post-receivepost-update 添加到repositories 路径为VonC suggested

[root@git-cd hooks]# pwd
/opt/gitlab-6.9.2-0/apps/gitlab/repositories/continuous-delivery/cd-test.git/hooks
[root@git-cd hooks]# ll
total 48
-rwxrwxr-x. 1 git git 452 Jun 10 06:01 applypatch-msg.sample
-rwxrwxr-x. 1 git git 896 Jun 10 06:01 commit-msg.sample
-rwxrwxr-x. 1 git git 44 Jun 11 00:37 post-receive
-rwxrwxr-x. 1 git git 41 Jun 11 00:38 post-update
-rwxrwxr-x. 1 git git 189 Jun 10 06:01 post-update.sample
-rwxrwxr-x. 1 git git 398 Jun 10 06:01 pre-applypatch.sample
-rwxrwxr-x. 1 git git 1642 Jun 10 06:01 pre-commit.sample
-rwxrwxr-x. 1 git git 1281 Jun 10 06:01 prepare-commit-msg.sample
-rwxrwxr-x. 1 git git 1352 Jun 10 06:01 pre-push.sample
-rwxrwxr-x. 1 git git 4972 Jun 10 06:01 pre-rebase.sample
lrwxrwxrwx. 1 git git 57 Jun 10 06:01 update -> /opt/gitlab-6.9.2-0/apps/gitlab/gitlab-shell/hooks/update
-rwxrwxr-x. 1 git git 3611 Jun 10 06:01 update.sample

这两个文件都包含一个脚本,该脚本将新行添加到现有文件 "post-receive-2">>/var/log/hooks_test.log。然后将更改从我的本地计算机推送到服务器。但它仍然没有附加文本。

更新 2

post-receive 中的脚本错误,没有回显。在我添加 echo (echo "post-receive-2">>/var/log/hooks_test.log 然后它按预期工作!

最佳答案

那是因为那些卫星存储库不是您要推送到的那个,所以它们的钩子(Hook)不会在您想到的时候触发(即,不是在有人推送到 GitLab 服务器时)。

PR 6185介绍架构概览文档

/home/git/gitlab-satellites - checked out repositories for merge requests and file editing from web UI. This can be treated as a temporary files directory.

The satellite repository is used by the web interface for editing repositories and the wiki which is also a git repository.

你应该在裸仓库中添加你的钩子(Hook) ~git/repositories .

或者(更新 2014 年第 4 季度,来自 GitLab 7.5+ Nov 2014 ),您可以使用 custom hooks (而不是 webhooks ),作为 mentioned below通过 Doka .

Custom git hooks must be configured on the filesystem of the GitLab server.
Only GitLab server administrators will be able to complete these tasks. Please explore webhooks as an option if you do not have filesystem access.

  • On the GitLab server, navigate to the project's repository directory.
    For a manual install the path is usually /home/git/repositories/<group>/<project>.git.
    For Omnibus installs the path is usually /var/opt/gitlab/git-data/repositories/<group>/<project>.git.
  • Create a new directory in this location called custom_hooks.
  • Inside the new custom_hooks directory, create a file with a name matching the hook type.
    For a pre-receive hook the file name should be pre-receive with no extension.
  • Make the hook file executable and make sure it's owned by git.

关于git - 如何将钩子(Hook)添加到 gitlab?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24154384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com