I am trying to set up a custom post-receive hook using gitlab
I am following their documentation here
I have an executable post-receive file in the custom_hooks folder with the following code:
!/bin/bash
echo "post-receive firing | wall
git pull
If I run this file with:
./post-receive
It works fine. It does not appear to fire at all when a push is made to the gitlab repo.
This is the first time I have ever tried web hooks of any kind so I am a little lost.
a) I have the above script on my remote webserver, inside the .git/custom_hooks folder, is this correct?
b) Do I need to do anything in the repo?
c) In the documentation, it specifies I should set permissions on the file so it is owned by the 'git' user. I have no git user on the webserver... all other git related files are owned by my user or root.
So assuming I am doing something completely wrong here, can someone please put me out of my misery and suggest a sane way to auto push to a web server whenever I push to gitlab from a local machine. I feel like I have spent some time looking for a way to do this and solutions seem to be complete overkill (cronjob running every few seconds...) or like the above, do not seem to work. Or at least I seem incapable of making them work.
Surely this is a straightforward task...
That is because oyur webserver is a client of the GitLab server.
The documentation you reference is for configuring a GitLab server (adding a post-receive hook to a GitLab repo). Hence the '
git
' user, which is the default one on a GitLab server.But if you are pushing to gitlab.com, you wouldn't add directly a hook.
You would need to declare a web hook, which would then send back a JSON message that you can listen to in order to trigger another action.
If you are the only one to push, you could simply push to multiple repos. No hooks involved there, client or server.
But that would be a local setting valid only for your local cloned repo.