You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
I am a project admin. I'll need to get with an administrator. I'll post as soon as I have an answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.