使用GitLab自定义收发后文件

Joh*_*pel 5 git gitlab

我正在尝试替换我的后接收挂钩,由GitLab自动生成一个新文件,该文件启用邮件支持,因此必须触发"post post".

这是我文件的先前版本:

#!/usr/bin/env bash

# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.

while read oldrev newrev ref
do
  # For every branch or tag that was pushed, create a Resque job in redis.
  repo_path=`pwd`
  env -i redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostRe
ceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}
" > /dev/null 2>&1
done
Run Code Online (Sandbox Code Playgroud)

当我用一个新文件替换该文件时,该文件包含文件末尾的上述行,GitLab说:"项目在管理区域中有无效的接收后文件",但电子邮件被正确发送.

你知道如何处理多个post-receive支持的问题.目前我不知道文件的gitlab特定部分是否正确执行.

感谢帮助!

更新:

现在使用下面提到的解决方案(拉取请求)调用文件夹中的脚本.但我不明白为什么标准的"post-receive-email"-script如果包含在目录中则不发送任何邮件.如果直接作为post-receive调用它,它可以正常工作.

不知道为什么我必须更改订单,但以下工作对我来说(即使我不知道现在是否正确创建了resque作业:

#!/usr/bin/env bash

repo_path=`pwd`

if [ -d hooks/post-receive.secondary.d ]; then

  for i in hooks/post-receive.secondary.d/*
  do
      [ -x "$i" ] || continue
      # call the hooklet with the same arguments we got
      path=$repo_path"/"$i
      "$path" "$@" || {
          # hooklet failed; we need to log it...
          echo hooklet $i failed
          perl -I$GL_BINDIR -Mgitolite -e "log_it('hooklet $i failed')"
          # ...and send back some non-zero exit code ;-)
          exit 1
      }
  done

fi

while read oldrev newrev ref
do
  # For every branch or tag that was pushed, create a Resque job in redis.
  env -i redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}" > /dev/null 2>&1
done

exit 0
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 5

更新2014年,GitLab 不再使用gitolite:

正如下面提到西罗桑蒂利,现在有一个正式的方式设置自定义的钩子(GitLab 7.5.0+ 11月2014).

  1. 选择一个需要自定义git钩子的项目.
  2. 在GitLab服务器上,导航到项目的存储库目录.
    对于手动安装,通常是路径/home/git/repositories/<group>/<project>.git.
    对于Omnibus,通常会安装路径/var/opt/gitlab/git-data/repositories/<group>/<project>.git.
  3. 在此位置创建一个名为custom_hooks 的新目录.
  4. 在新custom_hooks目录中,创建一个名称与钩子类型匹配的文件.
    对于pre-receive钩子,文件名应该pre-receive没有扩展名.
  5. 使钩子文件可执行,并确保它由git拥有.
  6. 编写代码以使git钩子函数按预期方式运行.钩子可以是任何语言.确保顶部的"shebang"正确反映语言类型.
    例如,如果脚本在Ruby中,则可能是shebang #!/usr/bin/env ruby.

原始答案(2013年1月)

在GitLab使用更新后挂钩时,这个(允许自定义挂钩)已经使用pull请求555commit 2245a6bbe解决了.

你需要hooks/post-receive.secondary.d在gitolite和GitLab管理的git bare repo中声明一个.
将所有更新后的挂钩放在那里.

您可以修改gitolite 在该模型后发布的更新后挂钩:如果检测到,它将调用所有更新后挂钩.


问题是:

使用Gitolite V2,GitLab最终将该管理委托给Gitolite,因为您可以声明更新后的挂钩,Gitolite本身会调用它.

使用Gitolite V3,不再有任何保留挂钩(除了gitolite-admin repo中的更新一个),因此没有gitolite"辅助"机制.
但GitLab(现在使用post-receive hook)尚未更新其钩子管理以考虑新的现实(gitolite不再允许二次钩子).


Cir*_*四事件 5

自定义挂钩

GitLab最近添加了一个自定义钩子功能,因为常规钩子在内部使用:https://github.com/gitlabhq/gitlabhq/blob/667c0a909bde1cf71f21d8ec9768e98b1c489030/doc/hooks/custom_hooks.md

基本上,你只需custom_hooks在你的Git仓库中创建一个目录并将钩子放入其中,GitLab确保它们运行.