如何向 gitlab 添加钩子? [英] How can I add hooks to gitlab?

查看:45
本文介绍了如何向 gitlab 添加钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 /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.

I setup a new Gitlab on CentOs on /opt/gitlab-6.9.2-0/apps/gitlab/ and created a new repository under continuous-delivery group. The full path is /opt/gitlab-6.9.2-0/apps/gitlab/gitlab-satellites/continuous-delivery/cd-test . There is only one file under this path which is README.txt.

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

What I try to achieve is to create a new file when somebody pushes changes to the server. Below are what I have done on the server:

  1. .git/hooks/' 下创建 post-updateupdate 文件,每个文件使用echo "text" 创建一个新文件 >> 文件名`
  2. 将它们更改为 775.
  1. Create post-update and update files under .git/hooks/' each file creates a new file usingecho "text" >> file_name`
  2. chmod them to 775.

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

When I push changes from my local to the server, there is no file being created. So, I would like to know what I have to do to fix this problem.

更新 1

我将 post-receivepost-update 添加到 repositories 路径为 建议使用 VonC

I added post-receive and post-update to repositories path as 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.然后将更改从我的本地计算机推送到服务器.但它仍然没有附加文本.

Both file contains a script that adds a new line to an existing file, "post-receive-2" >> /var/log/hooks_test.log. then pushed changes from my local machine to the server. But it still doesn't append the text.

更新 2

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

Script in post-receive was wrong, it didn't have echo. After I added echo (echo "post-receive-2" >> /var/log/hooks_test.log then it works as expected!

推荐答案

那是因为那些卫星仓库不是你要推送的那个,所以它们的钩子不会在你想的时候触发(即,不是什么时候有人正在推送到 GitLab 服务器).

That would be because those satellite repos aren't the one you would push to, so their hook aren't trigger when you would think (ie, not when someone is pushing to the GitLab server).

PR 6185 介绍架构概述文档

/home/git/gitlab-satellites - 从 Web UI 检查合并请求和文件编辑的存储库.这可以被视为一个临时文件目录.

/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.

网络界面使用卫星存储库来编辑存储库,而 wiki 也是一个 git 存储库.

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

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

You should add your hook in the bare repos ~git/repositories.

或者(2014 年第四季度更新,来自 GitLab 7.5+ Nov 2014),您可以使用 自定义挂钩 (而不是 webhooks),正如 Doka 下文所述.

Or (update Q4 2014, from GitLab 7.5+ Nov 2014), you can use custom hooks (instead of webhooks), as mentioned below by Doka.

必须在 GitLab 服务器的文件系统上配置自定义 git 挂钩.
只有 GitLab 服务器管理员才能完成这些任务.如果您没有文件系统访问权限,请探索 webhook 作为一个选项.

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.

  • 在 GitLab 服务器上,导航到项目的存储库目录.
    对于手动安装,路径通常是 /home/git/repositories/<group>/<project>.git.
    对于 Omnibus 安装,路径通常是 /var/opt/gitlab/git-data/repositories/<group>/<project>.git.
  • 在此位置创建一个名为 custom_hooks 的新目录.
  • 在新的 custom_hooks 目录中,创建一个名称与挂钩类型匹配的文件.
    对于 pre-receive 挂钩,文件名应为 pre-receive 且不带扩展名.
  • 使钩子文件可执行并确保它归 git 所有.
  • 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.

这篇关于如何向 gitlab 添加钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆