Is it possible to create branches and commits with a bitbucket server plugin?

We have a single repository (call it base) that is used as a submodule in about 10 other repositories.

Whenever changes occur to base, commits and pull requests have to be created for all 10 places it is used to update the link. A rather tedious process.

We have Jira integrated so i was thinking that while viewing a commit or branch in base, a UI could be invoked that asks for a jira number and then automatically creates branches, commits and pull requests for all the apps and sets everything up so it gets attached to the jira number so they can be reviewed and merged into the correct integration branches.

Is it possible to use the BB server plugin architecture to make something like this happen?


yes, certainly possible. I assume the next question will be: how? I use shell scripts in my development environment to achieve similar goals. That’s obviously specific to me and my layout but the building blocks all exist via git and REST. Via a plugin you’d probably need an event listener as your catalyst. Then a web-item keyed off a condition set by your listener then a service that executes the git interactions in each of the specified repos. Since there are REST endpoints for most of that I assume there are corresponding APIs. I’ve used jGit or in my plugins.

Who’s creating the issue? Maybe a post commit hook that creates the issue and uses the resulting issue key to drive the rest of the changes. If the issue creation is external then you need to jump through a lot of hoops so you can provide the key. Oh unless you control the workflow in jira then you can have a transition with a workflow-function in jira that calls the service in BB.

As far as who is creating the issue, it will probably be a preexisting task that is tracking the changes that necessitated the submodule updates. I am imagining a “button” in Jira somewhere? It might work as a state transition.

It sounds like this will be two plugins then …a jira plugin for the “button” and another one that does the work in stash.

Thanks for your suggestions. This will give me a lot of stuff to think about.

It’s certainly possible! My add-on (bit-booster) creates rebases, squashes, cherry-picks and reverts in a secret on-server fork, and then pushes them back into the main repo.

The trick for me (after setting up a special cached local clone directly on the server for the add-on to use) was realizing I needed to use “HookRequestHandle” before doing the “git push”. Kinda looks like this:

sloh = new SingleLineOutputHandler();
HookRequestHandle hrh = hookService.registerRequest(fromRepo.getId());
GitScmCommandBuilder commitCmd = gitScm.getCommandBuilderFactory().builder().command("commit");

// [various things here for my "git commit" command...]

HookUtils.configure(hrh, commitCmd);
cmd =;
String result =;

Good luck! There’s also lots of great examples to learn more about the Bitbucket API out there. For example, YACC (especially @bturner’s advice on Issue #139), or my in-progress PR for Auto-Unapprove.

I guess I’m a bit of a @bturner fan… :wink:


Please how do you get the gitScm object ?

GitScmCommandBuilder commitCmd = gitScm.getCommandBuilderFactory().builder().command("commit");

Fyi my script is triggered by a PullRequestMergedEvent event.


1 Like