Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

how to implement ScriptRunner for commit/pull request, merge check for complex branches in BitBucket


I am having a lot of issues or not understand enough about how to implement the pre-hook in BitBucket using ScriptRunner.  I have many but following are the first 3 cases:

we are using this kind of branching scheme:




The pre-hook for Branch and tag naming standards enforcement seems to work fine in the statement: master/feature/(proj1|proj2|proj3)/[A-Z]{2,9}-\d+.*

Case 1:
The Require commits to be associated with a valid Jira issue doesn't work in the JQL clause template: (issuetype = feature OR issuetype = Story OR issuetype = Bug OR issuetype = Sub-Task) AND (status = 'In Progress' OR status = 'In Review'))

Case 2: 
It also doesn't work for Require that pull request associated with a valid Jira issue:
Condition: (mergeRequest.pullRequest.fromRef.displayId.matches("release/.*") || mergeRequest.pullRequest.fromRef.displayId.matches("master/.*")) &&
!(mergeRequest.pullRequest.toRef.displayId.matches("develop/.*") || mergeRequest.pullRequest.toRef.displayId.matches("feature/.*"))

JQL clause template: issuetype = (issuetype = feature OR issuetype = Story OR issuetype = Bug OR issuetype = Sub-Task) AND (status = 'In Progress' OR status = 'In Review')
Case 3: 
Merge Check, how do I implement a check so that you can't only merge from develop/proj1 to /release/proj1 and /release/proj1 to /master/proj1 but can't not merge from proj1 to be or proj2 to proj3?
How do I make it work?  Is there a good tutorial somewhere or training that I can take?  Can we implement in bash or perl script and inject it to scriptRunner instead of using groovy?
Thank you.

1 answer

Cases 1. 2. Can I confirm if you already set up the Jira application link as documented in Adaptavist site?

Case 2. Following part of your condition:


probably should be: 


Please note that: the condition is not for a condition to reject a pull request, instead it is a condition to check for valid Jira issue.

Case 3. You can create a "Conditional merge check" that use similar condition in your case (2). Just be mindful that: In your condition, "fromRef" refers to source branch, "toRef" refers to target branch.

I hope this helps.

Thank you so much for your response.

Case 1. 2. Yes, Jira application link was established and is working properly.

Case 2. I will try that to see if it will work; however, I think it may still not know the Jira issue information because of the complexity level of the branch.

For Case 3.  I did something like this it seems to work but I'm not sure if it's working correctly yet:

def toBranch = mergeRequest.pullRequest.toRef.displayId
def fromBranch = mergeRequest.pullRequest.fromRef.displayId

def str1 = toBranch.split('/')[1];
def str2 = fromBranch.split('/')[1];

if (str1 == str2) {
     return false;
} else {
     return true;

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events