Cancelling any change in merge strategy with help of event handler in scriptrunner

With Bitbucket Server 4.9, repository admins can choose which merge strategies to allow, and set a default merge strategy.
The current, default, merge strategy ensures that merge commits are created after merging a pull request. These record the pull request number and branch name, helping to tie the merge back to a JIRA and a code review. Removing these commits may remove some valuable audit information.

We are trying to make an event handler ( repository modificationevent ) that will cancel the modification to repository if the merge strategy is changed from the default one .

We can also look at the possibility of hiding the UI web element of the merge strategies altogether.


Need some directions on this . 


1 answer

1 accepted

1 vote

I looked at this and it appears when you change those merge strategies there is no cancellable event so you can't prevent them from being changed. It seems the only way around this for now is to hide the merge strategies using some JavaScript.

You can do this by using the "install web resource" Script Fragment in ScriptRunner for Bitbucket Server.

It should look like the screenshot below:

Screen Shot 2017-01-12 at 09.49.34.png

You will need to place the following JavaScript code in a file called hideMergeStrategies.js:

(function ($) {
    AJS.toInit(function () {
        var $mergeStrategiesHeader = $('h3:contains("Merge strategies")');
        // hide merge strategy header
        // hide merge strategy paragraph
        // hide merge strategy options

You will need to set the system property "plugin.resource.directories" to a particular directory if you haven't already and place the JavaScript file there.

Let us know how you get on with this or if you require further help.

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

706 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