I setup a new Gitlab on CentOs on /opt/gitlab-6.9.2-0/apps/gitlab/
and created a new repository under continuous-delivery group. The full path is /opt/gitlab-6.9.2-0/apps/gitlab/gitlab-satellites/continuous-delivery/cd-test
. There is only one file under this path which is README.txt.
What I try to achieve is to create a new file when somebody pushes changes to the server. Below are what I have done on the server:
post-update
and update
files under .git/hooks/' each file creates a new file using
echo "text" >> file_name`When I push changes from my local to the server, there is no file being created. So, I would like to know what I have to do to fix this problem.
Update 1
I added post-receive
and post-update
to repositories
path as VonC suggested
[root@git-cd hooks]# pwd
/opt/gitlab-6.9.2-0/apps/gitlab/repositories/continuous-delivery/cd-test.git/hooks
[root@git-cd hooks]# ll
total 48
-rwxrwxr-x. 1 git git 452 Jun 10 06:01 applypatch-msg.sample
-rwxrwxr-x. 1 git git 896 Jun 10 06:01 commit-msg.sample
-rwxrwxr-x. 1 git git 44 Jun 11 00:37 post-receive
-rwxrwxr-x. 1 git git 41 Jun 11 00:38 post-update
-rwxrwxr-x. 1 git git 189 Jun 10 06:01 post-update.sample
-rwxrwxr-x. 1 git git 398 Jun 10 06:01 pre-applypatch.sample
-rwxrwxr-x. 1 git git 1642 Jun 10 06:01 pre-commit.sample
-rwxrwxr-x. 1 git git 1281 Jun 10 06:01 prepare-commit-msg.sample
-rwxrwxr-x. 1 git git 1352 Jun 10 06:01 pre-push.sample
-rwxrwxr-x. 1 git git 4972 Jun 10 06:01 pre-rebase.sample
lrwxrwxrwx. 1 git git 57 Jun 10 06:01 update -> /opt/gitlab-6.9.2-0/apps/gitlab/gitlab-shell/hooks/update
-rwxrwxr-x. 1 git git 3611 Jun 10 06:01 update.sample
Both file contains a script that adds a new line to an existing file, "post-receive-2" >> /var/log/hooks_test.log
. then pushed changes from my local machine to the server. But it still doesn't append the text.
Update 2
Script in post-receive was wrong, it didn't have echo. After I added echo (echo "post-receive-2" >> /var/log/hooks_test.log
then it works as expected!
GitLab Webhooks allows using Webhook notifications for all of the major lifecycle events in the software development process. It can trigger Webhooks for Code Push Events, Issue Changes, Comments, Merge Requests, Pipeline Events, Wiki Page Events, Deployment Events, Release Events, etc.
To install the hook, you can either create a symlink to it in . git/hooks , or you can simply copy and paste it into the . git/hooks directory whenever the hook is updated. As an alternative, Git also provides a Template Directory mechanism that makes it easier to install hooks automatically.
That would be because those satellite repos aren't the one you would push to, so their hook aren't trigger when you would think (ie, not when someone is pushing to the GitLab server).
PR 6185 introduced the archicture overview documentation
/home/git/gitlab-satellites
- checked out repositories for merge requests and file editing from web UI. This can be treated as a temporary files directory.The satellite repository is used by the web interface for editing repositories and the wiki which is also a git repository.
You should add your hook in the bare repos ~git/repositories
.
Or (update Q4 2014, from GitLab 7.5+ Nov 2014), you can use custom hooks (instead of webhooks), as mentioned below by Doka.
Custom git hooks must be configured on the filesystem of the GitLab server.
Only GitLab server administrators will be able to complete these tasks. Please explore webhooks as an option if you do not have filesystem access.
- On the GitLab server, navigate to the project's repository directory.
For a manual install the path is usually/home/git/repositories/<group>/<project>.git
.
For Omnibus installs the path is usually/var/opt/gitlab/git-data/repositories/<group>/<project>.git
.- Create a new directory in this location called
custom_hooks
.- Inside the new
custom_hooks
directory, create a file with a name matching the hook type.
For apre-receive
hook the file name should bepre-receive
with no extension.- Make the hook file executable and make sure it's owned by
git
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With