Hi
I am facing a problem while creating a pre-receive hook and don’t know how to solve it, please help.
I have a pre-receive hook, in which I need to perform some actions and if necessary show an error in the web interface.
In the simplest script it works correctly and the message is visible in the gitlab interface.
But if you add curl call to the script, then instead of custom message you see only “Prevented by server hooks” every time.
At the same time curl itself works correctly and if you make a push through the console, you see an error like “GL-HOOK-ERR: My custom error message.”.
What could be the reason?
Example 1 (this script shows the correct message in the web interface)
#!/bin/bash
while read oldrev newrev ref
do
OLD_COMMIT=$(git rev-parse $oldrev)
echo "GL-HOOK-ERR: My custom error message $OLD_COMMIT";
exit 1
done
Example 2 (this script shows the incorrect message in the web interface - “Prevented by server hooks”, but the NAME is output correctly if you do the push through the console)
#!/bin/bash
while read oldrev newrev ref
do
OLD_COMMIT=$(git rev-parse $oldrev)
NAME=$(curl --request GET --header "PRIVATE-TOKEN: glpat-Xxxx" http://192.168.1.87/api/v4/projects | jq -r '.[0].name_with_namespace')
echo "GL-HOOK-ERR: My custom error message $NAME";
exit 1
done
Configuration
I have a completely standard configuration in the docker
version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ce:16.10.6-ce.0
container_name: gitlab2
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
# Add any other gitlab.rb configuration here, each on its own line
external_url 'http://gitlab.example.com'
letsencrypt['enabled'] = false
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- /c/temp/gitlab/config:/etc/gitlab
- /c/temp/gitlab/logs:/var/log/gitlab
- /c/temp/gitlab/data:/var/opt/gitlab
shm_size: '256m'
Versions
16.10.6
- Self-managed
- GitLab.com SaaS
- Self-hosted Runner