我正在尝试用一个启用邮件支持的新文件替换我的 post-receive 钩子,它由 GitLab 自动生成,因此必须触发“post-receive”。
这是我的文件的以前版本:
#!/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
当我用一个新文件替换该文件时,该文件在文件末尾包含上述行,GitLab 在管理区域中说:“项目具有无效的后接收文件”,但电子邮件已正确发送。
您知道如何处理多个接收后支持的问题吗?目前我不知道文件的 gitlab 特定部分是否正确执行。
感谢帮助!
更新:
现在使用下面提到的解决方案(拉取请求)调用文件夹中的脚本。但我不明白为什么标准的“post-receive-email”脚本如果包含在目录中就不会发送任何邮件。如果直接作为 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