Problem in getting issue keys using Scriptrunner

Hi,

 

I am trying to enforce PullRequest policy enforcement using SCriptrunner plugin. I am trying to follow document https://scriptrunner.adaptavist.com/stash/latest/docs/event_handlers/#update-all-related-jira-issues-when-pull-request-opened. this line mentioned in the tutorial doesn't help me. Code breaks at this line.

def keys = jiraIssueService.getIssuesForPullRequest(repository.id, pullRequest.id)*.key

I tried to read documentation, but as per all odcs this is correct format.

 

Can you please suggest some alternative method or help me in fixing in same method?

 

3 answers

0 vote

What errors are you seeing in the logs after the script runs?

If your running Bitbucket and not stash, you need to replace "stash" in the imports with "bitbucket", for example: 

import com.atlassian.applinks.api.ApplicationLinkResponseHandler
import com.atlassian.bitbucket.event.pull.PullRequestOpenedEvent
import com.atlassian.bitbucket.integration.jira.JiraIssueService
import com.atlassian.plugin.PluginAccessor
import com.atlassian.sal.api.UrlMode
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.onresolve.scriptrunner.canned.bitbucket.util.StashBaseScript
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

Yes, I have already replaced imports for Bitbucket. I get this error message , "Pull request creation was canceled.

  • A event handler failed to execute properly - contact an Administrator".  Please see my code below. I have put values which I am getting as comment. I am using Scriptrunner for other restrictions too, I have never faced this type of problem.
import com.atlassian.applinks.api.ApplicationLinkResponseHandler
import com.atlassian.plugin.PluginAccessor
import com.atlassian.sal.api.UrlMode
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.bitbucket.event.pull.PullRequestOpenedEvent
import com.atlassian.bitbucket.integration.jira.JiraIssueService
import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketBaseScript
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

@BaseScript BitbucketBaseScript baseScript

//PullRequestOpenedEvent event = event

def pluginAccessor = ComponentLocator.getComponent(PluginAccessor.class)
def jiraIssueService = pluginAccessor.getEnabledPluginModule(ScriptRunnerImpl.PLUGIN_KEY + ":jiraIssueService").getModule() as JiraIssueService
//jiraIssueService=com.atlassian.bitbucket.internal.integration.jira.DefaultJiraIssueService@441068c9 
def pullRequest = event.getPullRequest()
//0
def repository = pullRequest.fromRef.repository
//437
assert pullRequest

def keys = jiraIssueService.getIssuesForPullRequest(repository.id, pullRequest.id)*.key

 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

178 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you