I`ve got a "library" with common functions, .../scripts/util/Helper.groovy:
package util
import .......
public class Helper {
public String getCurrentProjectKey() {
return issue.projectObject.key
}
}
And a script .../scripts/myscript.groovy:
import util.Helper
def helper = Helper
String currentProjectKey = helper.getCurrentProjectKey()
I use it as a post-function. But everytime I get an error or while checking either when running. The main problem is that "issue" object is not seen in library. I use different combination of code to make the "issue" object be recognizable, but nothing helps me...
For example, error:
file:/var/atlassian/application-data/jira/scripts/util/Helper.groovy: 29: Apparent variable 'issue' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'issue' but left out brackets in a place not allowed by the grammar.
How can I use "issue" object in my imported common libraries?
Or how can I get the current issue object?
Thanks in advance.
Hi Maksim,
I suppose one way is to pass the issue as a parameter. For example your Helper class would be something like
import com.atlassian.jira.issue.MutableIssue
class Helper {
static String getCurrentProjectKey(MutableIssue issue ) {
issue.projectObject.key
}
}
and then your script something like
import static myExampleScripts.util.Helper.*
def projectKey = getCurrentProjectKey()
log.debug "Project Key is $projectKey"
PS. I would be really interested to know what kind of helper methods you use ...
Kind regards,
Thanos
Hello Thanos!
Thank you for reply, I will try your advice,
I want to use common methods like getCurrentProjectRoles and others. I use different scripts, so I dont want to use same code in every script.
Is it possible to do something like:
import myExampleScripts.util.Helper
def helper = Helper(issue)
def currentIssueAssignee = helper.getCurrentIssueAssignee()
Is there any way an issue object to give to the class on its init and then use it in functions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Maksim,
Sure, you can. So in that case the Helper class will be
import com.atlassian.jira.issue.MutableIssue
class Helper {
private MutableIssue issue
Helper(MutableIssue issue) {
this.issue = issue
}
String getCurrentProjectKey() {
issue.projectObject.key
}
}
And then you script will look like
import myExampleScripts.util.Helper
def helper = new Helper(issue)
def projectKey = helper.getCurrentProjectKey()
log.debug "Project Key is $projectKey"
I edited my first answer in order to make it more readable.
Regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.