Bitbucket Server GUI bypassing git server side hook?

We have configured a server side pre-receive hook to enforce a naming convention for the branch name. It works as expected when doing a push from local to server (source tree), where it doesn't allow developer to push a new branch with invalid name to the server.

But, if developer decided to use Bitbucket UI (Web) to create the branch, this hook is being bypassed, where developer can name the new branch to anything. Does Bitbucket UI not use the push to make changes to the Git server? or it is disabling/bypassing the pre-receive hook with some other mechanism. 

 

Any way to prevent Bitbucket UI from bypassing pre-receive hooks?

1 answer

1 accepted

1 vote

The pre-receive hook will only get executed when you commit changes and do a git push to the server. If you are creating branches through the web UI you should add an event handler for the com.atlassian.bitbucket.event.branch.BranchCreationRequestedEvent.

To get the branch name you can do:

event.getBranch().getDisplayId()

Then to block creation you need to call:

event.cancel("Cancelling branch creation")

Additionally the current release of ScriptRunner for Bitbucket Server provides this functionality out of the box. Please see here for details of this.

Hope this helps.

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
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...

1,936 views 1 5
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