Access development information from groovy script-runner in workflow transition

Mikhail Leonov September 1, 2016

Hi,

We are using JIRA Software, Bitbucket Server, Bamboo Server. I'd like to trigger a specific bamboo build after a JIRA workflow transition. To do these I want to gather additional information from the issue, like last successful build, assignee and.. Bitbucket branch.

I already tried access these data via script-runner as mentioned here https://gist.github.com/jechlin/99f0853f579c7e4edb34 but realized that this solution only applicable if we are using Bitbucket cloud or Github. It will not work if we work with Bitbucket Server

In general, I have a two ideas of how I can access development data(such as branch, pull-request, e.t.c):

  1. via Bitbucket application link
  2. via Java API of "jira-software-plugin"

The question is, where I can find an API of "jira-software-plugin" or can someone helps me with accessing data via application link?

Thank you,

Best,

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Mikhail Leonov September 20, 2016

I, finally, found a solution of my problem!

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.plugin.devstatus.api.DevStatusSummaryService
import com.atlassian.jira.plugin.devstatus.rest.DetailBean
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.jira.plugins.jira-development-integration-plugin")
DevStatusSummaryService devStatusSummaryService = ComponentAccessor.getOSGiComponentInstanceOfType(DevStatusSummaryService.class)

ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

DetailBean pullRequestData = devStatusSummaryService.getDetailData(issue.id, "stash", "pullrequest", currentUser).get()

 

pullRequestData object will contain information about pull-requests and branches of the issue. You could use the same approach for accessing bamboo builds data as well.

Thank you all,

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 20, 2016

Hi Mikhail,

Glad you got it working. I came across that plugin while investigating this and it seems that you can't access the source code for it. It looks like its one of those you need to unzip the JAR for and decompile to see whats going on.

Nice use of @WithPlugin.

Thanks,
Adam 

Manjunatha K R December 12, 2016

Thanks Mikhail for sharing this nice script.

I am using SVN sub-version and would like to get the branches of the issue(i,e to which are all branches JIRA issue Fix is submitted) using pullRequestData object. 

DetailBean pullRequestData = devStatusSummaryService.getDetailData(issue.id, "subversion", "pullrequest", user).get()

can you please suggest how to get the 'branches of the issue'(s) details and compare with one custom field to match with. Thanks. 

Manjunatha K R December 13, 2016

I added the script as part of project workflow scripted post-function and got the below output after adding the below line::

DetailBean pullRequestData = devStatusSummaryService.getDetailData(issue.id, "subversion", "pullrequest", user).get()

log.debug(pullRequestData)

2016-12-13 16:44:44,497 DEBUG [workflow.ScriptWorkflowFunction]: com.atlassian.jira.plugin.devstatus.rest.DetailBean@31731dd9[detail=[],errors=[],configErrors=<null>]

3 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2016

Your best off tagging your question with com.onresolve.jira.groovy.groovyrunner to get a faster response. Not all of us follow the tags you mentioned or the tags in the questions you linked to.

It sounds like what you want to achieve can be done with a scripted post-function in JIRA. You will then need to call the bamboo REST API via an application link between JIRA and Bamboo to trigger a build. You can find examples here of interacting with other Atlassian applications.

The Bamboo REST API is documented here and the Bitbucket REST API is here.

Its just a case of putting it all together but hopefully this will give you an idea of how to approach this problem.

Mikhail Leonov September 1, 2016

Hi Adam, thank you for the response.

Yes, I used scripted post function. Yes, I used application link to communicate with Bamboo. And there are no problems at this point.

The problem is on the issue "parameters", precisely pull-request, branch name, and changeset that available in the development panel(Jira Software). As I mentioned in the question, I see a few ways how to do this, but I don't have enough expertise to find a correct way smile 

2 votes
ralfeus March 16, 2018
DevStatusSummaryService devStatusSummaryService = ComponentAccessor.getOSGiComponentInstanceOfType(DevStatusSummaryService.class)

I tried this script but devStatusSummaryService is null. I checked that  plugin com.atlassian.jira.plugins.jira-development-integration-plugin is installed and all its modules are enabled. 

What else can be done?

ralfeus March 19, 2018

I've found another way to get instance of DevStatusSummaryService:

 

def ccm = ComponentAccessor.getComponentClassManager()
def service = ccm.newInstance("com.atlassian.jira.plugin.devstatus.impl.DefaultDevStatusSummaryService")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-2")
def details = service.getDetailData(issue.id, "stash", "pullrequest", currentUser).right().get().getDetail()
Like # people like this
0 votes
Mikhail Leonov September 18, 2016

Hi Jamie,

"dvcsPullRequestService.getPullRequests(["MY_JIRA_ISSUE_ID"])" returns an empty result for my issue linked with Bitbucket server :(

As I understand, dvcs plugin is responsible for connections with Bitbucket cloud and github only.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 8, 2016

Are you sure it doesn't work for BB server? I think it does.

0 votes
Mikhail Leonov September 1, 2016

Another question with this topic: https://answers.atlassian.com/questions/9390795

Related to Github and Bitbucket Cloud integration. Doesn't helps me smile

0 votes
Mikhail Leonov September 1, 2016

The similar question was found here https://answers.atlassian.com/questions/39785152 and it still without answer sad

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events