Enable gitlab server hook

Hi,

I have followed steps mentioned @Git - githooks Documentation
and Server hooks | GitLab
but these server hooks are not getting triggered. Do I need to check some more configuration?

I have created a custom_hooks directory under @hashed/c3/0c/c30c6b3aa67e279b98c942a593aff6c832957388.git and added pre-receive file. Made this enabled to gitlab users and executable

chown git:git pre-receive
chmod +x pre-receive

ls -l pre-receive
-rwxr-x–x. 1 git git 331 Feb 26 00:59 pre-receive


#!/usr/bin/env bash

echo “we are in server hooks”
exit 20
pattern=‘refs/heads/dev-[0-9]-[a-z]’

while read oldrev newrev refname; do
if [[ $refname =~ ^refs/heads/dev ]]; then
if [[ ! $refname =~ $pattern ]]; then
echo “Blocking creation of new branch $refname”
echo “Because it does not match pattern $pattern”
exit 1
fi
fi
done
exit 10


I have even trued with “#!/bin/sh” as first line. Nothing worked.
according to above code my push should be rejected “exit 20” but it is getting accepted. Please help

Thanks

looks good to me; how about custom_hooks? is it +x as well?

Hi @Jie ,

Thanks for looking into it. Yes I think it was because of some permission.

Now it is working. the only difference is that. this time instead of creating a file, I copied file from hooks directory into “custom_hooks” directory. so with the file all its properties got copied.

1 Like