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

import jira classes into bitbucket


I need to use ComponentAccessor in scripts listeners for Bitbucket by Scriptrunner. I get error - unable resolve class after import. Is there a way to load jira class?

1 answer

Hi @artafon ,

Please can you provide a sample of the code that you are currently getting an error with, so I can debug it for you?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi @Robert Giddings _Adaptavist_ 

Thx for your attention. Below code returns - unable to resolve class ComponentAccessor

package examples.bitbucket.handler

import com.atlassian.jira.component.ComponentAccessor
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.bitbucket.pull.PullRequest
import com.atlassian.bitbucket.event.ApplicationEvent
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

import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer

import static*
import static*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
import groovy.json.JsonOutput

@BaseScript BitbucketBaseScript baseScript

int transitionId = 1111
def inputTransition //json выполнения автоперехода
def assignUser //json назначения исполнителя
List rev=[]
def targetGitRepos = ["test_reb_bb"]
PullRequest pullRequest = event.getPullRequest()
def repository = pullRequest.fromRef.repository
assert pullRequest
String projectPR = repository.getProject().name
String reponame =
def keys = jiraIssueService.getIssuesForPullRequest(,*.key

//***** start logging"event: " + event)"reponame: " + reponame)" " +" " +"keys: " + keys)"projectPR: " + projectPR)"repository: " + repository)
//***** end logging
if (targetGitRepos.contains(repository.slug)) {
def review=pullRequest.getReviewers()
def k = 0
String b = review[k].getUser().getName()

inputTransition = new JsonBuilder(
transition: [
id: transitionId

if (rev != null){
assignUser = new JsonBuilder(
name: rev[0]).toString()
//***** start logging"reviewer = " + rev[0])"assignee json = " + assignUser)
//***** end logging
def jiraLink = getJiraAppLink()
def authenticatedRequestFactory = jiraLink.createImpersonatingAuthenticatedRequestFactory()

for (String key in keys) {
if (key.substring(0, key.lastIndexOf("-")) == "TESTTEST") {
.createRequest(Request.MethodType.POST, "/rest/api/2/issue/$key/transitions")
.addHeader("Content-Type", "application/json")
handle: { Response response ->
if (response.successful) {
log.debug "Issue transit success: $key."
} else {
log.warn "Failed to transit issue: $response.responseBodyAsStream"
String body="<font size = 1em color = #b35900>[Данное письмо сформировано автоматически, не нужно на него отвечать]</font><br>"
body=body+"<b>Задача не в статусе Проверка кода " + key + "<br>"
def subject = "Невозможно перевести задачу в статус - Проверка кода"
//sendEmail (key.getReporter().getEmailAddress(), subject, body)
}] as ApplicationLinkResponseHandler<Void>
if (assignUser != null){
.createRequest(Request.MethodType.PUT, "/rest/api/2/issue/$key/assignee")
.addHeader("Content-Type", "application/json")
handle: { Response response ->
if (response.successful) {
log.debug "Assign user on issue: $key."
} else {
log.warn "Failed to assign user: " + response.getResponseBodyAsStream()
}] as ApplicationLinkResponseHandler<Void>

//отправка уведомления автору запроса о задачах, которые не перевелись в статус - Проверка кода
/*def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(emailAddr);
} else {
// Problem getting the mail server from JIRA configuration, log this error

Hi @artafon ,

Sorry for the late response.

The first thing to solve is that ComponentAccessor is a Jira class:


For Bitbucket you should use ComponentLocator:


Secondly, I see that you are wanting to use ComponentAccessor, because you are wanting to import in a Jira mail server manager into your ScriptRunner for Bitbucket Listener?

This, I don't think will work.

Instead I suggest the following. Either:

1) Set up a Post Function in Jira to send the email, following the transition.

2) Use ScriptRunner for Jira to setup a Custom REST Endpoint, which you can call from the ScriptRunner for Bitbucket Listener, in the same way as the standard Jira REST API.

3) Use Bitbucket's mail server manager and send the email directly from Bitbucket.

Please let me know if any of those suggestions help you progress?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

@Robert Giddings _Adaptavist_ Hi!

In post function I cann't send email because I need bitbucket data from PR. Custom end point from JIRA - that my solution. 

Thanks for your attention in my question. Happy new Year!

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events