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.atlassian.bitbucket.build.BuildStatusService
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.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ReturningResponseHandler
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: com.atlassian.bitbucket.build.BuildSummary#getSuccessfulCount()
@ 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.
ildStatusService.getSummaries(event.pull
Any assistance would be appreciated.
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
@Robert Giddings _Adaptavist_ I'm try to work with an administrator. What exactly needs added to the global ScriptRunner config?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.