Global custom hooks

Hello!
I’ve read about global custom hooks in documentation (https://docs.gitlab.com/ee/administration/custom_hooks.html#chained-hooks-support). But some issues aren’t clear enaough for me.

  1. Can I create symlink from some folder to .git/custom_hooks/? If not, why?
  2. In what order are hooks from .git/custom_hooks/<hook_name>.d/* and .git/hooks/<hook_name>.d/* run?
  3. Where I should create global custom hooks? Documentation says about: .git/hooks/<hook_name>.d/. In /opt/gitlab/embedded/service/gitlab-shell/hooks/<hook_name>.d/? If I create them here, won’t next GitLab upgrade overwrite them?

I’d like to create one location with many scripts run in loop as different hooks (just like in this solution http://stackoverflow.com/questions/8730514/chaining-git-hooks/8734391#8734391) and in each project make custom_hooks folder as a symlink from that earlier mentioned location. And I’d like to make it only for few groups (it would be automated by system hooks for new projects), no for every project (as global custom hooks).

I will appreciate any help.

Any help?

I’m not an expert, but I have been looking into things in this area. I can try help with a couple of your questions:

  1. In what order are hooks from .git/custom_hooks/.d/* and .git/hooks/.d/* run?
    It is sorted numerical and alphabetical, for the exact definition see: Class: String (Ruby 2.4.1)
    The code to find the hooks is in the ‘match_hook_files’ method in: https://gitlab.com/gitlab-org/gitlab-shell/blob/master/lib/gitlab_custom_hook.rb
  2. Where I should create global custom hooks? Documentation says about: .git/hooks/.d/. In /opt/gitlab/embedded/service/gitlab-shell/hooks/.d/? If I create them here, won’t next GitLab upgrade overwrite them?
    It should be: /opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.d/ (or update/post-receive). I thought I was reading that there is a mechanism to prevent the hooks from being removed on upgrades, but I can’t find that text now, so I can’t confirm on that.

I too tried to configure the pre-receive hook to prevent some file type pushing/committing in the origin.

For this, I created the pre-receive.d file in the exact location and added the below two line to check if the hook working or not,

#!/usr/bin/env bash
echo "test bash hook"

But I didn`t get the above text in the git push screen. How can I confirm is this hook working or not?

@arunkumar
You should create folder /opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.d/ and create there any hook file. Of course user gitlab should be able to execute it.

1 Like