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

查看:3461
本文介绍了如何添加钩子到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。



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


  1. 创建更新后 update 下的 .git / hooks /'文件创建一个新文件使用 echotext>> file_name

  2. 将更改从我的本地服务器推送到服务器时,将其修改为775.


$ b <没有正在创建的文件。



更新1



我添加了后接收后更新 / code>路径作为 VonC建议

  [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更新后
-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 36​​11 Jun 10 06:01 update.sample

两个文件都包含一个脚本,行到现有文件,post-receive-2>> /var/log/hooks_test.log 。然后将更改从本地计算机推送到服务器。


$ b

更新2

在后接收是错误的,它没有回声。在我添加echo( echopost-receive-2>> /var/log/hooks_test.log 后,它会按预期工作!

解决方案

这将是因为那些卫星回复不是你要推送的,所以他们的钩子不会触发,当你想(即,不是当有人推送到GitLab服务器时)。



PR 6185 介绍了archicture概述文档


/ home / git / gitlab -satellites - 从网络用户界面中检出合并请求和文件编辑的存储库。这可以作为临时文件目录。



卫星存储库由Web界面用于编辑存储库和wiki也是一个git存储库。


您应该在



或者(更新2014年第4季度,从 GitLab 7.5+ 2014年11月),您可以使用 自定义钩子 (而不是 webhooks ),作为 多卡



< blockquote>

自定义git钩子必须在GitLab服务器的文件系统上配置。

只有GitLab服务器管理员才能完成这些任务。如果您没有文件系统访问权限,请浏览webhooks。




  • 在GitLab服务器上,导航到项目的存储库目录。 >
    对于手动安装,路径通常是 / home / git / repositories /< group> /< project> .git

    对于Omnibus安装,路径通常是 / var / opt / gitlab / git-data / repositories /< group> /< project> .git 。 >
  • 在此位置创建名为 custom_hooks 的新目录。

  • 在新 custom_hooks 目录中,创建一个名称与钩子类型匹配的文件。

    对于预接收名称应为预接收,不带扩展名。

  • 将hook文件设置为可执行文件,并确保它由 git



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

Update 1

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

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.

Update 2

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!

解决方案

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 introduced the archicture overview documentation

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

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

Or (update Q4 2014, from GitLab 7.5+ Nov 2014), you can use custom hooks (instead of webhooks), as mentioned below by 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.

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

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