Can scriptrunner prevent branch deletion through the UI?

Is there a way to use ScriptRunner to prevent branch deletion performed through the UI? (for stash versions prior to 3.10 which don't have this support built-in).

I can see it's possible with a pre-receive hook, but I think this wouldn't prevent a delete through the UI. I had a look through the event hooks but I couldn't see a CancelableEvent for branch deletion. 

2 answers

Hi Baris,

ScriptRunner events are categorised in cancelable and non-cancelable sections in the Script Event Handlers functionality.

If you use the Script Event Handler functionality and create a custom BranchDeletionRequestedEvent then it should be canceleable, please see this link:

https://developer.atlassian.com/static/javadoc/bitbucket-server/4.0.3/api/reference/com/atlassian/bitbucket/event/branch/BranchDeletionRequestedEvent.html

I hope that helps.

 

 

Ah, thank you! The link to this from the adaptavist documentation was broken (I see you have fixed this now - thank you) and my own googling 'Atlassian CancelableEvent' took me here which on reflection is obviously (from the URL) out of date.

 

Hm - I don't have "Custom event handler" available - is that because it's not enabled for me for my repo, or is this not possible at the repo level?

(I do have available other standard actions in response to events)

0 vote

Hi Baris,

Branch permissions in later versions allows you to control who can delete branches. Take a look at https://confluence.atlassian.com/display/BitbucketServer/Using+branch+permissions

For your existing version, you might find the below link helpful.

https://marketplace.atlassian.com/plugins/com.sarav.stash.hooks.protectbranches.ProtectBranches/server/overview

Hope that helps.

Right. Not sure about ScriptRunner but you might find this helpful. It is compatible with the version you are running.

https://marketplace.atlassian.com/plugins/com.sarav.stash.hooks.protectbranches.ProtectBranches/server/overview

Maybe time for an upgrade wink

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 06, 2018 in Bitbucket

Do you use Bitbucket Cloud and Jira Cloud? If so, let us know!

Hi Community, I'm Julia and I'm on the Jira Software Cloud marketing team!  We're looking for companies or teams using Bitbucket Cloud and Jira Software Cloud. If your team fits the t...

151 views 6 3
Join discussion

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