PreReceiveHook and PostReceiveHook are not invoked

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Symptoms

When using the Atlassian SDK to run Bitbucket Server 2.0.x on Mac or Linux, the onReceive() method on a PreReceiveHook or PostReceiveHook is not triggered when pushing to the default repository (PROJECT_1 / rep_1). Branch permissions (which are implemented as PreReceiveHooks) will also not work for rep_1.

Cause

The hook scripts in the rep_1 repository in the default bitbucket-plugin-test-resources.zip setup by AMPS doesn't have the executable permissions set. git-receive-pack ignores non-executable scripts, so no hooks are invoked when you push to rep_1.

Resolutions

(The quick way) Create a new repository

Any new repositories will have their hook scripts correctly initialised, so the easiest way to workaround this issue is simply to create a new repository for testing your plugin.

That's it! Hooks should now work correctly for the newly created repository.

(The slightly longer way) Manually set the script permissions

  1. From your plugin directory, navigate to /target/bitbucket/home/data/repositories/1/hooks

  2. Run ls -l *

  3. You should see the following output:

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 tpettersen@hoprocker ~/example-plugin/target/bitbucket/home/data/repositories/1/hooks (BARE:master) $ ls -l -r * -rw-r--r-- 1 tpettersen staff 3611 20 Dec 00:35 update.sample -rw-r--r-- 1 tpettersen staff 1239 20 Dec 00:35 prepare-commit-msg.sample -rw-r--r-- 1 tpettersen staff 424 20 Dec 00:35 pre-receive -rw-r--r-- 1 tpettersen staff 4951 20 Dec 00:35 pre-rebase.sample -rw-r--r-- 1 tpettersen staff 1704 20 Dec 00:35 pre-commit.sample -rw-r--r-- 1 tpettersen staff 398 20 Dec 00:35 pre-applypatch.sample -rw-r--r-- 1 tpettersen staff 189 20 Dec 00:35 post-update.sample -rw-r--r-- 1 tpettersen staff 426 20 Dec 00:35 post-receive -rw-r--r-- 1 tpettersen staff 896 20 Dec 00:35 commit-msg.sample -rw-r--r-- 1 tpettersen staff 452 20 Dec 00:35 applypatch-msg.sample pre-receive.d: total 8 -rw-r--r-- 1 tpettersen staff 410 20 Dec 00:35 20_bitbucket_callback post-receive.d: total 8 -rw-r--r-- 1 tpettersen staff 412 20 Dec 00:35 20_bitbucket_callback
  4. Run chmod -R a+x *

  5. Run ls -l * again

  6. You should see the following output (note the scripts are now executable):

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 tpettersen@hoprocker ~/example-plugin/target/bitbucket/home/data/repositories/1/hooks (BARE:master) $ chmod -R a+x * tpettersen@hoprocker ~/example-plugin/target/bitbucket/home/data/repositories/1/hooks (BARE:master) $ ls -l * -rwxr-xr-x 1 tpettersen staff 452 20 Dec 00:35 applypatch-msg.sample -rwxr-xr-x 1 tpettersen staff 896 20 Dec 00:35 commit-msg.sample -rwxr-xr-x 1 tpettersen staff 426 20 Dec 00:35 post-receive -rwxr-xr-x 1 tpettersen staff 189 20 Dec 00:35 post-update.sample -rwxr-xr-x 1 tpettersen staff 398 20 Dec 00:35 pre-applypatch.sample -rwxr-xr-x 1 tpettersen staff 1704 20 Dec 00:35 pre-commit.sample -rwxr-xr-x 1 tpettersen staff 4951 20 Dec 00:35 pre-rebase.sample -rwxr-xr-x 1 tpettersen staff 424 20 Dec 00:35 pre-receive -rwxr-xr-x 1 tpettersen staff 1239 20 Dec 00:35 prepare-commit-msg.sample -rwxr-xr-x 1 tpettersen staff 3611 20 Dec 00:35 update.sample post-receive.d: total 8 -rwxr-xr-x 1 tpettersen staff 412 20 Dec 00:35 20_bitbucket_callback pre-receive.d: total 8 -rwxr-xr-x 1 tpettersen staff 410 20 Dec 00:35 20_bitbucket_callback
  7. Your commit hooks will be triggered on the next push to rep_1.

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.