How To Fix Gitlab With No Push Events And Branch

Our self-deployed Gitlab(v8.7) show no push event and branch on the website after git push, while the code repository is actually updated. I search for a while and found there are many people have the same issue, and many open issue related to this problem, especially those who deployed gitlab from source. I figured out how to fix it after a thorough investigation and here is what to do.

Here what gitlab actually do for each git push. It basically trigger a post-receive hook to notify sidekiq to generate push event for this operation and they communicate via Redis. Here is the workflow for this procedure.

First Check

The very first thing to do is check your gitlab environment works as expected.1

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production  

Hooks

First make sure hooks are correctly located in git

[root@host git]# ls gitlab-shell/hooks/                                                                            
post-receive  pre-receive  update  

Second check if there is a symlink pointing to /home/git/gitlab-shell/hooks for each repository, like this:

[root@host git]# ll repositories/yourname/example.git/
total 48  
drwxrwxr-x   2 git git 4096 Jul 16 11:44 branches  
-rw-rw-r--   1 git git   66 Jul 16 11:44 config
-rw-rw-r--   1 git git   73 Jul 16 11:44 description
-rw-rw-r--   1 git git   23 Jul 16 11:44 HEAD
lrwxrwxrwx   1 git git   31 Jul 16 11:44 hooks -> /home/git/gitlab-shell/hooks  
drwxrwxr-x   2 git git 4096 Jul 16 11:44 hooks.old.1468640682  
drwxrwxr-x   2 git git 4096 Aug 26 18:10 info  
drwxrwxr-x 110 git git 4096 Aug 27 10:30 objects  
-rw-rw-r--   1 git git  337 Aug 26 18:10 packed-refs
drwxrwxr-x   4 git git 4096 Jul 16 11:44 refs  
-rw-rw-r--   1 git git 8673 Aug 27 10:30 update.log

Otherwise you need to run gitlab-shell/bin/create-hooks command to make them.

You may modify post-receive hooks to log something to make sure it is triggered as expected, like this:3

#!/usr/bin/env ruby  
# post-receive
# This file was placed here by GitLab. It makes sure that your pushed commits  
# will be processed properly.  

refs = ARGF.read  
key_id  = ENV['GL_ID']  
repo_path = Dir.pwd  

# reset GL_ID env since we already got its value  
ENV['GL_ID'] = nil  

require_relative '../lib/gitlab_custom_hook'  
require_relative '../lib/gitlab_post_receive'  

if GitlabPostReceive.new(repo_path, key_id, refs).exec &&  
    GitlabCustomHook.new.post_receive(refs, repo_path)
# Print some log here  
  open('/tmp/post.log','w') do |f|  
    f << "#{refs},#{key_id},#{repo_path}\n"  
  end  
  exit 0  
else  
  exit 1  
end  

You should have something in /tmp/post.log after you push to repository now.

Redis

redis config for gitlab-shell and sidekiq is located in gitlab-shell/config.yml and gitlab/config/resque.yml. Do double check they are connecting to the same redis instance. Here is what they normally have:

[root@host git]# cat gitlab-shell/config.yml
---
user: git  
gitlab_url: http://gitlab.yourdomain.com/  
http_settings:  
  self_signed_cert: false
repos_path: "/home/git/repositories/"  
auth_file: "/home/git/.ssh/authorized_keys"  
redis:  
  bin: "/usr/local/bin/redis-cli"
  db: 0
  namespace: resque:gitlab
  socket: "/var/run/redis/redis.sock"
log_level: INFO  
audit_usernames: false  
[root@host git]# cat gitlab/config/resque.yml
development: redis://localhost:6379  
test: redis://localhost:6379  
production: unix:/var/run/redis/redis.sock  

You may check whether it works by issuing the following command:

/usr/bin/redis-cli -h localhost -p 6379 rpush 'resque:gitlab:queue:post_receive' '{"class":"PostReceive","args":["/repositoriespath/projectname.git/hooks","","","branch-or-tag-name","user-myusername"]}'

Sidekiq

Make sure sidekiq is running:

sudo -u git -H RAILS_ENV=production bin/background_jobs status  

Check if sidekiq fetching task from redis by watching its log.

tail -f gitlab/log/sidekiq.log  

Push code to your gitlab now and sidekiq should have something in log like:

2016-08-27T02:30:11.909Z 24223 TID-ouv325z6o PostReceive JID- INFO: start  
2016-08-27T02:30:12.081Z 24223 TID-ouv325z6o PostReceive JID- INFO: done: 0.171 sec  

Reference

Guimin Lin

Read more posts by this author.