Added a comment: gitlab post-receive hook

master
ac_w 2021-05-06 11:38:32 -04:00 committed by admin
parent 885102612a
commit 1461e2a3c9
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
[[!comment format=mdwn
username="ac_w"
avatar="http://cdn.libravatar.org/avatar/a76f89f70fffde5fbdacaa2a0438d8d9"
subject="gitlab post-receive hook"
date="2021-05-06T15:38:16Z"
content="""
Concerning the post-receive hook that I mentioned in the previous comment, it turned out I didn't have to bother with webhooks. Even though it's a bit out of the scope of this topic, here is how to do it:
- Find the hashed name of the repository in the Admin Area of gitlab. ([see details](https://docs.gitlab.com/ee/administration/repository_storage_types.html#from-project-name-to-hashed-path))
- `mkdir /var/opt/gitlab/git-data/repositories/@hashed/<group_hash>/<repo_hash>.git/custom_hooks` ([see details](https://github.com/gitlabhq/gitlabhq/blob/667c0a909bde1cf71f21d8ec9768e98b1c489030/doc/hooks/custom_hooks.md))
- create `/var/opt/gitlab/git-data/repositories/@hashed/<group_hash>/<repo_hash>.git/custom_hooks/post-receive` with the following content :
```bash
#!/bin/sh
git log -1 --format=format:%ae HEAD | grep -e '@web$' -e 'ikiwiki' || wget \"https://<wiki_url>/ikiwiki.cgi?do=ping\" -O -
```
(without the shebang it doesn't work, also I had to remove the `/dev/stdout` part otherwise the shell complains git can't write to it)
- `chown -R git:root /var/opt/gitlab/git-data/repositories/@hashed/<group_hash>/<repo_hash>.git/custom_hooks`
- `chmod +x /var/opt/gitlab/git-data/repositories/@hashed/<group_hash>/<repo_hash>.git/custom_hooks/post-receive`
"""]]