Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


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

Auto-merge pull request if approved and build successful

I'm currently working in bitbucket 7.20, I trying to use ScriptRunner to have pull requests auto-merged if there are 2 approvals and the build is successful.  I've been able to get the approvals, but haven't been able to get the build status back for a pull request.  


Here is the code I'm trying to use:


import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.bitbucket.event.pull.PullRequestParticipantApprovedEvent
import com.atlassian.bitbucket.integration.jira.JiraIssueService
import com.atlassian.bitbucket.pull.PullRequest
import com.atlassian.bitbucket.pull.PullRequestMergeRequest
import com.atlassian.bitbucket.pull.PullRequestService
import com.atlassian.bitbucket.user.SecurityService
import com.atlassian.bitbucket.util.Operation
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketBaseScript
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.transform.BaseScript
import com.atlassian.bitbucket.scm.pull.MergeRequest

@BaseScript BitbucketBaseScript baseScript

def buildStatusService = ComponentLocator.getComponent(BuildStatusService)
def securityService = ComponentLocator.getComponent(SecurityService)
def pullRequestService = ComponentLocator.getComponent(PullRequestService)

def pullRequests = []
def repository = null
def execute_branch = ["feature/OSC-1818-Test-Branch"]
def summaries = buildStatusService.getSummaries(event.pullRequest.getCommits()*.id)
def successfulBuild = summaries.values().find {it.successfulCount > 0}


This code won't compile once it is saved.  It throws the following errors: 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script22.groovy: 32: [Static type checking] - You tried to call a method which is not allowed: java.util.Map #values()
@ line 32, column 23.
def successfulBuild = summaries.values().find {it.successfulCount > 0}

Script22.groovy: 32: [Static type checking] - You tried to call a method which is not allowed:
@ line 32, column 48.
ld = summaries.values().find {it.success

Script22.groovy: 31: [Static type checking] - Property is not allowed: java.lang.Iterable #id
@ line 31, column 49.


Any assistance would be appreciated.

1 answer

Hi @cwoody ,

Thank you for your post.

Please can you confirm if you are a Project or Repository Admin? As currently some Bitbucket objects are not available for use directly by Project or Repository Admins.

Does your script work, if you are able to get a Bitbucket Administrator to add it to the global ScriptRunner config?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

I am a project admin.  I'll need to get with an administrator.   I'll post as soon as I have an answer.

@Robert Giddings _Adaptavist_  I'm try to work with an administrator.  What exactly needs added to the global ScriptRunner config?

Hi @cwoody ,

Sorry for the late reply!

To answer your last question -

Whatever ScriptRunner object you were trying to create in ScriptRunner at the Project level (I assume it is a Listener?), you need to ask a global administrator to create the same type of ScriptRunner object in the global admin area of Bitbucket and use your Script.

Your global admin's have more permissions allowing them to run less restrictive code, which is what is currently causing your Script errors.

Please let me know if that helps answer your question? Or if you need more help?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events