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:
- Create
post-update
andupdate
files under.git/hooks/' each file creates a new file using
echo "text" >> file_name` - chmod them to 775.
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!
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
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.
See Custom Git Hooks - GitLab Documentation for the official way to do it.
Summary: As of gitlab-shell version 2.2.0 (which requires GitLab 7.5+), GitLab administrators can add custom git hooks to any GitLab project.
/home/git/repositories/<group>/<project>.git
For Omnibus installs the path is usually/var/opt/gitlab/git-data/repositories/<group>/<project>.git
custom_hooks
.custom_hooks
directory, create a file with a name matching the hook type. For a pre-receive hook the file name should bepre-receive
with no extension.#!/usr/bin/env ruby
.But do see the link above for the official docs. The above is a snapshot as it was today...
As of gitlab-shell version 2.2.0 (which requires GitLab 7.5+), GitLab administrators can add custom git hooks to any GitLab project. So you have to upgrade, and follow the instructions from here: https://docs.gitlab.com/ce/administration/custom_hooks.html