如何在GitLab版本 12.6.0-ee 中配置全局git钩子?(The gitlab-shell hooks have been migrated to Gitaly)

在/opt/gitlab/embedded/service/gitlab-shell/hooks 目录下pre-receive显示

#!/bin/sh
echo "The gitlab-shell hooks have been migrated to Gitaly, see https://gitlab.com/gitlab-org/gitaly/issues/1226"
exit 1

  所以pre-receive变位置了

但是全局的配置暂时还是没有生效,

单个库的配置还是和以前一样:

<repositories>.git 下面新建custom_hooks

 

 然后在custom_hooks 里面新建自定义的hook:

set -x
z40=0000000000000000000000000000000000000000
while read oldrev newrev refname; do
  echo 'old version:'${oldrev}
  echo 'new version:'${newrev}
  echo 'branch:'${refname}
  branch="$(echo $refname|awk -F '/' '{print $3}')"
   if [ "$newrev" = $z40 ]
        then
        # Handle delete
        :
        else
		if [ "$oldrev" = $z40 ]
		then
				# New branch, examine all commits
				range="$newrev"
		else
				# Update to existing branch, examine new commits
				range="$oldrev..$newrev"
		fi
		# Check for dev/test merged commit
		release_commit=$(git rev-list -n 1  --grep '.git into' "$range")
		if [ -n "$release_commit" ]
		then
            echo >&2 "Found [$branch merged] commit, push rejected!!!"
            exit 1
		fi
    fi
done
echo >&2 "prevent branch merged by $branch check passed"
set +x

  

  

 

posted @ 2021-02-24 17:16  零零柒  阅读(365)  评论(0编辑  收藏  举报