Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

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

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

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!

Leaderboard

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
4,552,760
Community Members
 
Community Events
184
Community Groups

Post Function to update Fix Version unable to import ComponentAccessor

Hi,

I have just installed the cloud plugin for script runner and trying my first script. 

 

I have the following code and error:

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)

def versions = versionManager.getVersions(project)

def versionNoCodeChange = versions.find( it.name.equals('no-code-change') )

issue.setFixVersions(Arrays.asList(versionNoCodeChange))
2018-06-26 09:13:29.540 ERROR - startup failed:
Script1.groovy: 1: unable to resolve class com.atlassian.jira.component.ComponentAccessor
 @ line 1, column 1.
   import com.atlassian.jira.component.ComponentAccessor
   ^

1 error

2018-06-26 09:13:29.579 ERROR - Class: com.adaptavist.sr.cloud.workflow.UpdateIssue, Config: [className:com.adaptavist.sr.cloud.workflow.UpdateIssue, uuid:cfe72c36-d292-4a17-99a5-ef39821aceb2, description:Set fix-version to no-code-change, enabled:true, executionUser:INITIATING_USER, additionalCode:import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)

def versions = versionManager.getVersions(project)

def versionNoCodeChange = versions.find( it.name.equals('no-code-change') )

issue.setFixVersions(Arrays.asList(versionNoCodeChange)), userKey:mitch.kent]

 

This is, as I say, from the post-function screen.

 

I've searched and there are many posts around this functionality, but all seem to use the ComponentAccessor which I can't get, so am stuck on first hurdle.

 

Many thanks,

Mitch.

2 answers

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 29, 2018

Hi Mitch,

I can confirm that your code is from the ScriptRunner for Jira Server plugin and the Jira Cloud version.

The reason for that is that the cloud version can only make changes to Jira via the Atlassian Rest API's as cloud does not have a Java API like the server version does.

This is described in more detail in the documentation page located here.

In order to set the version field for an issue inside of a post function on a cloud instance then you will need to use the Run Script post function which is described in the documentation here.

I have created some example code which shows how you can get the set the fix versions on an issue during a post function which can be viewed here. This code will show you how to set versions and can be used to create the script that you require.

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Hi Kristian,

Thanks for your response.

The reason for that is that the cloud version can only make changes to Jira via the Atlassian Rest API's as cloud does not have a Java API like the server version does.


I realise this is the case, but I wrongly presumed the script runner plugin wrapped these things up in its own library - having looked into it more since I realise how wrong this is :)

This does mean that everything will become vastly more complex after this single example, for any future stuff I would like to work on. As such, there is no point in me continuing with the plugin, and have disabled it.

I appreciate your answer, but I wont be able to use or test it, so I can't mark it as correct.

Regards,

Mitch.

0 votes
Alexey Matveev
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.
Jun 26, 2018

Hello,

You are writing a script for Scriptrunner for Jira Server Version. You can not use same scripts for Cloud and Server version. Cloud is built upon Rest calls. Kindly have a look at the documentation for ScriptRunner Cloud:

http://scriptrunner-docs.connect.adaptavist.com/jiracloud/

Thanks Alexey.

 

This looks massively more complicated and effort, though I can appreciate the reasons now I've read through the page.

 

I think I'll just delete the plugin.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events