From f82380b9df9693e7976b7474233840a469635429 Mon Sep 17 00:00:00 2001 From: Luke Duncalfe Date: Wed, 20 Mar 2019 17:08:51 +1300 Subject: Allow custom hooks errors to appear in GitLab UI Error messages from custom pre-receive hooks now appear in the GitLab UI. This is re-enabling a feature that had been disabled in merge request https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18646 The feature had been disabled due to security concerns that information which was not intended to be public (like stack traces) would leak into public view. PreReceiveErrors (from pre-receive, post-receive and update custom hooks) are now filtered for messages that have been prefixed in a particular way. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/48132 --- doc/administration/custom_hooks.md | 20 ++++++++++++++++---- doc/administration/img/custom_hooks_error_msg.png | Bin 44892 -> 80442 bytes 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'doc/administration') diff --git a/doc/administration/custom_hooks.md b/doc/administration/custom_hooks.md index 60ad4bf4e8f..28afaf84f5a 100644 --- a/doc/administration/custom_hooks.md +++ b/doc/administration/custom_hooks.md @@ -51,7 +51,7 @@ Hooks can be also placed in `hooks/.d` (global) or execution of the hooks. NOTE: **Note:** `.d` would need to be either `pre-receive.d`, -`post-receive.d`, or `update.d` to work properly. Any other names will be ignored. +`post-receive.d`, or `update.d` to work properly. Any other names will be ignored. To look in a different directory for the global custom hooks (those in `hooks/`), set `custom_hooks_dir` in gitlab-shell config. For @@ -76,9 +76,21 @@ first script exiting with a non-zero value. > [Introduced][5073] in GitLab 8.10. -If the commit is declined or an error occurs during the Git hook check, -the STDERR or STDOUT message of the hook will be present in GitLab's UI. -STDERR takes precedence over STDOUT. +To have custom error messages appear in GitLab's UI when the commit is +declined or an error occurs during the Git hook, your script should: + +- Send the custom error messages to either the script's `stdout` or `stderr`. +- Prefix each message with `GL-HOOK-ERR:` with no characters appearing before the prefix. + +### Example custom error message + +This hook script written in bash will generate the following message in GitLab's UI: + +```bash +#!/bin/sh +echo "GL-HOOK-ERR: My custom error message."; +exit 1 +``` ![Custom message from custom Git hook](img/custom_hooks_error_msg.png) diff --git a/doc/administration/img/custom_hooks_error_msg.png b/doc/administration/img/custom_hooks_error_msg.png index 845f0de19ce..4f25c471908 100644 Binary files a/doc/administration/img/custom_hooks_error_msg.png and b/doc/administration/img/custom_hooks_error_msg.png differ -- cgit v1.2.1