Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Side Hooks on Bitbucket

Tags:

git

githooks

I'm new to creating git hooks. I've successfully created a local git hook but I am having a hard time figuring out how to install a server side hook on Bitbucket.

I've tried using a plugin called External Hooks and making a External Pre Receive Hook, but that results in my push to Bitbucket being rejected with:

remote: Hook external-pre-receive-hook blocked the push ! [remote rejected] master -> master (pre-receive hook declined).

I've tried putting the hook in the .git folder on the server. But there's not a .git folder that I can find. I did find ApplicationData/Bitbucket/bin/git-hooks. I tried putting a pre-receive hook file in there but that was not successful. It did not prevent a push to the repo but the file also did not execute.

The hook/file that I'm using is as simple as can be so I don't think thats the problem. It has this text:

#!/bin/sh
#

echo 'hi there soldier'
like image 975
Patricia Green Avatar asked Aug 27 '17 18:08

Patricia Green


1 Answers

I found out where to add a pre-receive or post-receive hook on a repository basis by adding a file to the Bitbucket server. In the Atlassian folder, it is in ApplicationData\Bitbucket\shared\data\repositories\[repository#]\hooks\.

Bitbucket keeps track of repos internally using numbers and not names so in the above replace [repository#] with the repo number. That can be found out this way.

Put the pre-receive hook in the pre-receive.d folder. Put the post-receive hook in the post-receive.d folder.

The names of the hooks/files should begin with a number. That determines what order the hooks are 'activated'. Begin the numbers with at least 21 because the default hook in the folder begins with 20. You want your hook to be activated after the one shipped with Bitbucket server. So a file name for a pre-receive hook could be 21_pre_receive.

Don't change the default hooks that are in the folder because they are needed to help Bitbucket work.

More information can be found here.

like image 97
Patricia Green Avatar answered Nov 01 '22 16:11

Patricia Green