Upgrading ScriptRunner and Structure plugins on JIRA v7.2.9 gives unable to resolve class

My JIRA instance is using JIRA 6.4.5 with Structure 2.11.0.jira6 and ScriptRunner 3.0.16.

There is a groovy script accessing structure for validating data on a workflow.

This is all working well, but when JIRA is upgraded to

JIRA 7.2.9, Structure 3.5.1, ScriptRunner 4.3.16, the script fails with (I removed all the code except 2 lines of ScriptRunner and 3rd line of Structure, where it fails)

unable to resolve class com.almworks.jira.structure.api.StructureServices
 @ line 3, column 1.
   import com.almworks.jira.structure.api.StructureServices
   ^
1 error

 

I placed this script in the Scripts path, but no use. 

I feel I'm missing something at a fundamental level, but can't figure out what even after few hours. Any ideas what else can I try? 

2 answers

1 accepted

This widget could not be displayed.

The Structure 4.1.0 APIs are changed.

1. 

com.almworks.jira.structure.api.PermissionLevel is changed to 

com.almworks.jira.structure.api.permissions.PermissionLevel

2. StructureServices is now StructureComponents

APIs are here 

This widget could not be displayed.

There is a very similar error that was happening in this post https://community.atlassian.com/t5/Atlassian-Marketplace-questions/ScriptRunner-can-t-find-plugin-module/qaq-p/249144 The versions are not exactly the same as yours, but I think you're seeing the same kind of problem.

In that case it appears that this might be happening due to the way the script is written.  I would take a closer look at that post to see the example.  In that case, the @examplevalue was defined inside the contructor when it should have been defined outside.

Perhaps if you can post back with your script that generates this error, others in the community might be better able to guide how that script might need to be altered to make this work in the more recent versions of these plugins.

Thanks for your response.

The given link fails with "Invalid Parameters Specified". Can you repost the link?

The whole script (mostly from Jamie's samples) is below:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.version.Version
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.IssueManager

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.StructureServices
import com.almworks.jira.structure.api.StructureException
import com.almworks.jira.structure.api.PermissionLevel

import java.util.ArrayList
import java.util.Collection
import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

// Specify that classes from this plugin should be available to this script
@WithPlugin("com.almworks.jira.structure")

// Inject plugin module
@PluginModule
StructureServices structureServices

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def structureManager = structureServices.getStructureManager()

Issue _issue = issue
Long issueID = _issue.getId() // to be used in Structure

Collection<Version> fixVersions = new ArrayList<Version>()
fixVersions = _issue.getFixVersions()

if (fixVersions.size() != 1)
{
// JIRA 6.3+ Version
throw new InvalidInputException("There can be only one Fix Version for this issue in Planned state.")

//JIRA 5.2+ Version
//invalidInputException = new InvalidInputException("There can be only one Fix Version for this issue in Planned state.")
}
else
{
Version ver = fixVersions.iterator().next()
if ( (! ver.releaseDate) && (structureManager.isIssueInStructure(issueID, 100) ) ) // if fix version doesn't have a release data and is in a Structure instance
{
// JIRA 6.3+ Version
throw new InvalidInputException("This issue is in System SAR structure. So it's FixVersion must have a Release Date.")
//JIRA 5.2+ Version
//invalidInputException = new InvalidInputException("Either change the Fix Version to one with a Release Date or provide a Release Date to the input Fix Version.")
//invalidInputException = new InvalidInputException("This issue is in System SAR structure. So it's FixVersion must have a Release Date.")
}
}

When the above script is executed, I get the errors below on the workflow validator's execution information log:

2017-07-18 07:59:42,963 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-07-18 07:59:42,963 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: TESTNEWSAR-1697, actionId: 31, file: D:\CustomCodeScripts\Scripts\Groovy\PostFunction\jira1532FixVersionMandatoryOnlyWhenItIsPartofStructure.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/D:/CustomCodeScripts/Scripts/Groovy/PostFunction/jira1532FixVersionMandatoryOnlyWhenItIsPartofStructure.groovy: 9: unable to resolve class com.almworks.jira.structure.api.StructureServices
 @ line 9, column 1.
   import com.almworks.jira.structure.api.StructureServices
   ^
file:/D:/CustomCodeScripts/Scripts/Groovy/PostFunction/jira1532FixVersionMandatoryOnlyWhenItIsPartofStructure.groovy: 11: unable to resolve class com.almworks.jira.structure.api.PermissionLevel
 @ line 11, column 1.
   import com.almworks.jira.structure.api.PermissionLevel
   ^
file:/D:/CustomCodeScripts/Scripts/Groovy/PostFunction/jira1532FixVersionMandatoryOnlyWhenItIsPartofStructure.groovy: 10: unable to resolve class com.almworks.jira.structure.api.StructureException
 @ line 10, column 1.
   import com.almworks.jira.structure.api.StructureException
   ^
3 errors

Got moved to other tasks so I'm late by a week here.

I upgraded both plugins to their latest versions as the link above says and pointed the Script Console's RUN to a file in scripts path:

Structure: 4.1.0

Scriprunner: 5.0.14

and JIRA remains same at 7.2.9.

then I re-indexed, restarted but I still get the same error.

Anything else I can try here? The errors are below.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

file:/D:/JIRA729/scripts/testjira1532.groovy: 7: unable to resolve class com.almworks.jira.structure.api.StructureServices @ line 7, column 1. import com.almworks.jira.structure.api.StructureServices 

file:/D:/JIRA729/scripts/testjira1532.groovy: 3: unable to resolve class com.almworks.jira.structure.api.PermissionLevel @ line 3, column 1. import com.almworks.jira.structure.api.PermissionLevel

2 errors

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

527 views 3 19
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