本文介绍了如何添加钩子到gitlab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在 /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。 我尝试实现的是当有人将更改推送到服务器时创建一个新文件。以下是我在服务器上所做的: 创建更新后 update 下的 .git / hooks /'文件创建一个新文件使用 echotext>> file_name 将更改从我的本地服务器推送到服务器时,将其修改为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概述文档您应该在 或者(更新2014年第4季度,从 GitLab 7.5+ 2014年11月),您可以使用 自定义钩子 (而不是 webhooks ),作为 多卡。 自定义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:Create post-update and update files under .git/hooks/' each file creates a new file usingecho "text" >> file_name`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 1I 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]# lltotal 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.samplelrwxrwxrwx. 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.sampleBoth 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 2Script 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 documentationYou 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. 这篇关于如何添加钩子到gitlab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 19:22