Skip to content

Instantly share code, notes, and snippets.

@matrey
Last active April 29, 2018 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matrey/e4d3645af0918326d9d8 to your computer and use it in GitHub Desktop.
Save matrey/e4d3645af0918326d9d8 to your computer and use it in GitHub Desktop.
Multiple update hooks for Gitlab
#!/bin/bash
# The standard, global, Gitlab update hook
update_true_path="$(cd `dirname $(readlink $0)` && pwd)"
update_gitlab="$update_true_path/update"
# Additional, local, update.before and update.after hooks
hooks_dir="$(cd `dirname $0` && pwd)"
update_before="$hooks_dir/update.before"
update_after="$hooks_dir/update.after"
if [ -x $update_before ]; then
$update_before "$@" || exit 1
fi
$update_gitlab "$@" || exit 1
if [ -x $update_after ]; then
$update_after "$@" || exit 0
fi
@matrey
Copy link
Author

matrey commented Apr 29, 2018

Goals, on push:

  • be able to make additional blocking checks (forbidden files, files too large...) before Gitlab references the push --> update.before
  • be able to update external ticketing tools with commit details (errors shouldn't block the push) --> update.after

2 ways to implement it:

  1. repo by repo
  • Save update-multiple (below) into /opt/gitlab/embedded/service/gitlab-shell/hooks/update-multiple. Make executable.
  • Go into the repo's hooks folder then symlink update to this new update-multiple:
    rm update
    sudo -u git ln -s /opt/gitlab/embedded/service/gitlab-shell/hooks/update-multiple update
  1. global
  • Copy the original update file under a new name, e.g. update.gitlab
  • Replace the contents of the update file with update-multiple (below). Remember to edit line 5 (e.g. update_gitlab="$update_true_path/update.gitlab")

Tested on latest CentOS 6 + Gitlab omnibus package.
I haven't tested what happens in case you update Gitlab. Use at your own risk.

You can now add "update.before" and "update.after" scripts in the hooks folder of your repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment