本文主要是介绍gitlab中配置全局钩子,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
设置全局pre-receive hooks
vi /etc/gitlab/gitlab.rb
#打开下面配置
gitaly['custom_hooks_dir'] = "/var/opt/gitlab/gitaly/custom_hooks"
#保存退出
#创建钩子目录
mkdir -p /var/opt/gitlab/gitaly/custom_hooks/pre-receive.d
cd /var/opt/gitlab/gitaly/custom_hooks/pre-receive.d
创建钩子
vi git-commit-message-check
复制一下内容并保存
#!/bin/bashzeroCommit='0000000000000000000000000000000000000000'
mergeRegex='^(Merge)(.+)'
contentRegex='^(init|feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?(: .{1,})?'while read -r oldrev newrev refname; do# 未提交的分支为tag不检测[ "$newrev" = "$zeroCommit" ] && continue[ "$oldrev" = "$zeroCommit" ] && range="$newrev" || range="$oldrev..$newrev"for commit in $(git rev-list "$range" --not --all); douser=$(git log --pretty=format:"%an" $commit -1)commitDate=$(git log --pretty=format:"%cd" $commit -1)msg=$(git log --pretty=format:"%s" $commit -1)flagMerge=$(echo $msg | grep -E "$mergeRegex")flagPush=$(echo $msg | grep -E "$contentRegex")if [ -z "$flagPush" ] && [ -z "$flagMerge" ]; thenecho "[ERROR]日志:$msg"echo "[ERROR]提交信息检查不通过,请按照规范修改后重新提交"echo "[ERROR]提交者:$user"echo "[ERROR]提交日期:$commitDate"echo "[ERROR]$commit in ${refname#refs/heads/}"exit 1fidone
done
给钩子附执行权限
chmod +x git-commit-message-check
结果查看
提交项目文件,通过返回日志可以查看结果,或者
查看日志文件
/var/log/gitlab/gitaly/current
Gitaly配置文件的路径 (默认为/var/opt/gitlab/gitaly/config.toml)可通过此文件查看项目中一些基础目录的配置
这篇关于gitlab中配置全局钩子的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!