pre-receive hook

We have created a pre receive hook plugin for bitbucket server (roughly following the video tutorial https://developer.atlassian.com/blog/2015/01/beer-o-clock-stash-plugin-tutorial/) and the onReceive logic works perfectly for any push that's done from a git client (e.g. through manual "git push" command from CLI).

However, the hook is not getting triggered for any commit that's being done from the bit bucket GUI using the "Edit" feature.

We are using Bitbucket 5.5.1 DC edition.

1 answer

Hi,

In Bitbucket 5.0, we've introduced a new repository hooks API that allows you to intercept all changes to branches and tags using a unified API. The beer-o-clock blog post is still using the old, now deprecated, API, which does not support intercepting in-browser edits.

Fortunately, the new API does support it. You can find an extensive guide in our developer documentation.

For your use case, you should probably implement `PreRepositoryHook<RepositoryHookRequest>` and check the trigger on the request to determine whether you want to apply your hook's restrictions:

 

public class ExampleHook implements PreRepositoryHook<RepositoryHookRequest> {
@Nonnull
@Override
public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context,
@Nonnull RepositoryHookRequest request) {
if (!shouldIntercept(request.getTrigger()) {
return RepositoryHookResult.accepted();
}

// apply your hook logic here and return accepted() or rejected()

}

private boolean shouldIntercept(RepositoryHookTrigger trigger) {
// customize to include all triggers the hook should respond too
return trigger == StandardRepositoryHookTrigger.PUSH ||
trigger == StandardRepositoryHookTrigger.FILE_EDIT;
}

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

654 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot