Problem configuring pre-recieve server hook

Problem configuring pre-recieve server hook

We’ve just installed a fresh version of gitlab on my own server (v16.1.1-ee). Detailed info:

System information
System:
Proxy:          no
Current User:   git
Using RVM:      no
Ruby Version:   3.0.6p216
Gem Version:    3.4.13
Bundler Version:2.4.14
Rake Version:   13.0.6
Redis Version:  6.2.11
Sidekiq Version:6.5.7
Go Version:     unknown

GitLab information
Version:        16.1.1-ee
Revision:       d3582d7719f
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     PostgreSQL
DB Version:     13.11
URL:            http://gitlab.navarra.es
HTTP Clone URL: https://gitlab.navarra.es/some-group/some-project.git
SSH Clone URL:  git@gitlab.navarra.es:some-group/some-project.git
Elasticsearch:  no
Geo:            no
Using LDAP:     yes
Using Omniauth: yes
Omniauth Providers:

GitLab Shell
Version:        14.23.0
Repository storages:
- default:      unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell

I tried to follow this guide to set up a pre-receive hook : Server hooks | GitLab

In the gitlab.rb we set the new configuration for gitaly custom hooks after an error of deprecation configuration appears in the reconfigure:

gitaly['configuration'] = {
  hooks: {
    # gitaly['custom_hooks_dir']
    custom_hooks_dir: '/var/opt/gitlab/gitaly/custom_hooks'
  }
}

In the directory /var/opt/gitlab/gitaly/custom_hooks we’ve create a pre-recieve.d directory with a test hook:

[root@xxxxxxxxxxx gitaly]# vim custom_hooks/pre-receive.d/verifyCommiter

#!/bin/sh
echo "GL-HOOK-ERR: My custom error message.";
exit 1
~
~
~
~
~
"custom_hooks/pre-receive.d/verifyCommiter"

The hook is not working when pushes are made. Any idea about the problem?
Thank you.

Finally the problems were related to the permissions of the hook.

chmod +x hook
chown userWithPrivileges:userWithPrivileges hook

Now, it works.
Thanks

1 Like

I have tried the above solution but it is not working for me, i have followed the below steps. can you please suggest
chmod +x hook
chown git:git hook