It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Devtools Barclays Jan 10, 2017

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
Answer accepted
Adam Markham [Adaptavist] Community Leader Jan 11, 2017

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 Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

3,030 views 1 20
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you