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

Bitbucket Server: using ScriptRunner to change default settings for all new/forked repos within a project?

First, this question is regarding the Adaptavist ScriptRunner for Bitbucket Server plugin.  I tried to tag this question with the proper tag.

My organization is migrating to Bitbucket Server, and we will soon be having many repositories that users will be contributing to.

It appears that as of Bitbucket Server version v4.14.0, it is not possible to specify default settings for all new repositories created within a project.  All new repos (and even forked repos) look to take on the default settings chosen by Atlassian.

We would like to be able to have in each of our Bitbucket projects a ‘settings template’ repo.  Then, every new repo created in this project would get its settings copied from the ‘settings template’ repo.  (I am fine with the 'template' living somewhere else.)

These settings would include, for example:

Repo permissions, Branch permissions, Access keys, Hooks, Pull requests, Branching model, Default reviewers, and any settings from Add-Ons (if possible).

So, would this be possible when using the Adaptavist ScriptRunner for Bitbucket Server plugin?  It appears that I would want to trigger on both the "RepositoryCreationRequestedEvent" and "RepositoryForkRequestedEvent".

Otherwise, propagating the settings we need becomes a very manual and error prone process, it would be great to have a programmatic way to achieve this instead.

I personally don't have any experience with java or groovy, so I would probably need a bit of direction.  But first, I would like to know if this is possible with ScriptRunner.

Thank you, Jimmy



4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
adammarkham Community Leader Mar 02, 2017

This is possible with quite a bit of code though. Just wanted to clarify a bit.  Whenever a repository is created the event handler would copy all the repository settings etc based on another pre-existing repository?

We already have a built-in admin script which clones a repository here. It sounds like this is quite similar but just an event handler version of it?

It sounds like this is something we could build into the product for you, as I see this being very useful to automate standardisation across repositories.

Thank you, Adam. This is really good news and will help us standardize across many repos.

To your question, yes, we would like all newly created and newly forked repos to take on the settings based on a pre-existing repo ('template').

Somehow I had missed the 'Clone Repository' built-in script when I looked over the 'Admin Scripts' page. Would an event handler based version act any different?

Do you have a similar admin script for forks as well?  We noticed when forking repos that the forked repo had Atlassian's default settings.

Also to clarify, the 'Clone Repository' built-in script copies only the items given in the list "The following configuration items are replicated in the new repository" on this page?  I see some items missing, for example, merge strategy under pull requests, and hooks.

Finally, would we be able to override repository settings for existing repos beased on the same template?

Thank you!  --Jimmy





0 votes
adammarkham Community Leader Mar 03, 2017

We don't have an option to clone as a fork at the moment. I can see that it would be useful to have the same settings in the fork when it's created automatically.

An event handler version would automatically set the settings whenever a user created a new repository. The current version requires an admin to manually run the script to clone the repository first instead.

This was written some time ago before merge strategies and the additional pull request options were in Bitbucket. We're currently working on SRBITB-193 which will address this for you with it being released early next week.

I think there are two problems here:

  • Inheriting repository settings from the parent when you create a fork
  • Setting default repository settings when you create a repository in a particular project based on a template repository

Have you given any thought about how to keep them in sync? For example if the template settings change you'd want that to be reflected in all the repositories that have the template applied? It sounds like from your last question you don't want this and want to override them if necessary?


We are moving Bitbucket projects from one server to another server and merging the instances. If we use scriptrunner plug-in, can we get pull requests, permissions, repos, branches from old instance to new instance?




Hi Adam, thanks so much for this information.  I think we would be just fine to have an admin manually run the built-in script rather than using something custom.  I'm happy to see that the additional pull request options will be copied across as well!

Our use of forks will be less, but nevertheless would be interested to see if this capability is added to the built-in script in the future.

For the overrides, I hope that our need for this is very limited once our workflow is established.  If the template settings change, we may not want that change to be reflected in all repositories, it would be nice to handle it on a case-by-case basis.

Thanks again for your answers!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

Community showcase
Published in Atlassian Community Events

It is me, Andy B ! a.k.a. FUN MAN ANDY [Community Showcase]

COMMUNITY SHOWCASE – FUN MAN ANDY “Showcases spotlight Atlassian Leaders who make a big impact on our Community. The Atlassian Community Team taps Leaders to share more about themselves and their A...

157 views 10 9
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