| `GL_PROTOCOL` | (GitLab 13.2 and later) Protocol used for this change. One of: `http` (Git Push using HTTP), `ssh` (Git Push using SSH), or `web` (all other actions). |
| `GL_PROTOCOL` | (GitLab 13.2 and later) Protocol used for this change. One of: `http` (Git `push` using HTTP), `ssh` (Git `push` using SSH), or `web` (all other actions). |
| `GL_REPOSITORY` | `project-<id>` where `id` is the ID of the project |
| `GL_REPOSITORY` | `project-<id>` where `id` is the ID of the project. |
| `GL_USERNAME` | GitLab username of the user that initiated the push |
| `GL_USERNAME` | GitLab username of the user that initiated the push. |
Pre-receive and post-receive server hooks can also access the following Git environment variables.
The following Git environment variables are supported for `pre-receive` and `post-receive` server hooks:
@@ -155,26 +127,18 @@ Pre-receive and post-receive server hooks can also access the following Git envi
...
@@ -155,26 +127,18 @@ Pre-receive and post-receive server hooks can also access the following Git envi
| `GIT_PUSH_OPTION_COUNT` | Number of push options. See [Git `pre-receive` documentation](https://git-scm.com/docs/githooks#pre-receive). |
| `GIT_PUSH_OPTION_COUNT` | Number of push options. See [Git `pre-receive` documentation](https://git-scm.com/docs/githooks#pre-receive). |
| `GIT_PUSH_OPTION_<i>` | Value of push options where `i` is from `0` to `GIT_PUSH_OPTION_COUNT - 1`. See [Git `pre-receive` documentation](https://git-scm.com/docs/githooks#pre-receive). |
| `GIT_PUSH_OPTION_<i>` | Value of push options where `i` is from `0` to `GIT_PUSH_OPTION_COUNT - 1`. See [Git `pre-receive` documentation](https://git-scm.com/docs/githooks#pre-receive). |
NOTE:
While other environment variables can be passed to server hooks, your application should not rely on
them as they can change.
## Custom error messages
## Custom error messages
To have custom error messages appear in the GitLab UI when a commit is declined or an error occurs
You can have custom error messages appear in the GitLab UI when a commit is declined or an error occurs during the Git
during the Git hook, your script should:
hook. To display a custom error message, your script must:
- Send the custom error messages to either the script's `stdout` or `stderr`.
- 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.
- Prefix each message with `GL-HOOK-ERR:` with no characters appearing before the prefix.
### Example custom error message
For example:
This hook script written in Bash generates the following message in the GitLab UI:
```shell
```shell
#!/bin/sh
#!/bin/sh
echo"GL-HOOK-ERR: My custom error message.";
echo"GL-HOOK-ERR: My custom error message.";
exit 1
exit 1
```
```
![Custom message from custom Git hook](img/custom_hooks_error_msg.png)