requiring own gem in hooks

11 views
Skip to first unread message

Saku Ytti

unread,
Mar 11, 2015, 12:01:20 PM3/11/15
to gitl...@googlegroups.com
I believe this use-case applies to custom hooks too, but my use-case is modifying gitlab-shell hooks, so not exactly supported.


I want hook for all repos, so I'm calling my own class in post-receive, this works great.

However post-receive is not called for 'accept merge request' events, and I have one repo where this is only way it'll ever get commits. So I migrated my script to 'update' hook. It continues work great for 'push' events, but fails in 'merge' events. Reason it fails is, because my ruby file is requiring a gem, and this gem invariably fails with 'loaderror'.


I postulate this is because on 'push' event, ssh forks the ruby instance, so it'll see all normally installed gems. But on 'merge' event we're running inside gitlab ruby instance, which won't see it.

I tried to workaround this, by calling my ruby script via system(), but even in that case, it'll fail for LoadError on 'merge' events.



Is it possible to use your own gems in custom hooks? I believe this answer, once satisfied also applies to my unsupported use-case. 

Thanks,

Achilleas Pipis

unread,
Mar 12, 2015, 10:25:22 AM3/12/15
to gitl...@googlegroups.com

Saku Ytti

unread,
Mar 12, 2015, 11:26:59 AM3/12/15
to gitl...@googlegroups.com

On Thursday, 12 March 2015 16:25:22 UTC+2, Achilleas Pipis wrote:
To me LOAD_PATH didn't seem like cause of the issue, Only rationale I could come up with, if it's also chrooted?  

Saku Ytti

unread,
Mar 18, 2015, 2:47:53 PM3/18/15
to gitl...@googlegroups.com



To me LOAD_PATH didn't seem like cause of the issue, Only rationale I could come up with, if it's also chrooted?  


In pry I did
lp1 = $LOAD_PATH.dup 
require 'my/gem'
lp2 = $LOAD_PATH.dup
lp2-lp1

And I added those to my hook, and it started working for 'merge requests'. So it was LOAD_PATH issue, I just don't get what is stopping 'require' working normally in 'accept merge request'. And why does it work normally for 'push' event'.

Reply all
Reply to author
Forward
0 new messages