When running Groovy scripts, JMWE makes contextual information available to your script through built-in variables, functions, Component/Service Manager and Jira Standard Services. This document details them. Note that you can also define custom variables in your Groovy script.
On this page:
Table of Contents | ||||
---|---|---|---|---|
|
Available Variables
The variables are available in the:
...
originalIssue
The originalIssue
variable exposes the methods of the main Issue interface, including methods not native to Jira such as get(), getLinkedIssues() etc. It points to the current Issue object, as it was before the transition started. You can access the fields of the issue by accessing the properties and methods of this variable.
...
The textutils
variable is a utility object of class TextUtils providing useful methods to manipulate text and HTML. This is applicable only in the post-functions that use Groovy templating.
...
So when the issue is unassigned, the warning message is displayed in the atlassian-jira.log file.
Custom variables
In addition to the above variables, you can also define your own variables in the Groovy script.
For example, Condition to check whether the Fix Version/s has a particular version.
...
Variable name | Type | Description |
---|---|---|
| Deprecated. The | |
| Deprecated. The linkedIssue variable is a synonym for the relatedIssue variable. |
Note |
---|
In JMWE versions prior to 5.0.0, the |
Functions
The functions are available in the:
...
jqlSearch("<JQL expression>", <maxResults>)
is a simple function that you can use to search for issues using a JQL. The function expects the following:
JQL expression: A JQL query
maxResults: maximum number of issues to return
When you pass a valid JQL query and number of issues, the function returns a List<
Issue>
of issues that match the JQL.
Examples:
Fetch the first ticket of a specific project that has the same Cascading value set as of the current issue
Code Block language groovy issues = jqlSearch("project=TP and Cascade in CascadeOption(${issue.get("Cascade")?.get(null)?.getValue()},${issue.get("Cascade")?.get("1")?.getValue()})",1)
Fetch the first 10 issues that have the same Fix Version/s as the first Fix Version/s of the current issue.
Code Block language groovy def versions = issue.get("fixVersions") def issues = [] if (versions){ issues = jqlSearch("fixVersion = ${versions.first()}", 10) } issues
...
workdaysBetween(<Date from>, <Date to>)
is a global function that returns a Long representing the number of work days (excluding Saturdays and Sundays) between two Date objects. It returns null
if one of the two parameters is null
. For example:
Code Block language groovy workdaysBetween(issue.created, issue.duedate)
returns the number of days between the issue creation and the due date
Code Block language groovy workdaysBetween(issue.created, new Date())
returns the number of days from the issue creation to now.
...
Code Block |
---|
getOrganization('Appfire').usersInOrganization |
getTransitionAttachments()
getTransitionAttachments
is a global function that returns the Attachments that have been added on the transition or issue creation screen. The function returns a List<Attachment>.
Accessing any Component/Service Manager
...
getComponent(Class interface)
is a global function to get a Component/Service from Jira or any loaded add-on. The function expects a Class interface as the parameter. Until 5.1.0
importing classes from third party add-ons or some classes of Jira and its Java dependencies was not easy. You had to get the Class loader and find the class followed by getting the Component/Service. For example to get the RapidViewServiceInterface
you had to write the following code:
Code Block | ||
---|---|---|
| ||
import com.atlassian.jira.component.ComponentAccessor def classLoader = issue.get("Rank").getClass().getClassLoader() def RapidViewServiceIntf = classLoader.findClass("com.atlassian.greenhopper.service.rapid.view.RapidViewService") def RapidViewService = ComponentAccessor.getOSGiComponentInstanceOfType(RapidViewServiceIntf) |
...
You can access a few Standard Jira's services from the Groovy editor. Hover over any button to get the information, click on it to insert it into the editor.
Jira Standard Service | Returns | Example |
---|---|---|
AttachmentManager | Jira's AttachmentManager service. Manages all attachment related tasks in JIRA, which involves retrieving an attachment, creating an attachment and deleting an attachment. | Copy attachments from the current issue to issue whose key is TEST-123
|
ChangeManager | Returns Jira's ChangeHistoryManager service, which manages the change history of issues.ChangeHistoryManager | To get the change history of the current issue:
|
ConstantsManager | Returns Jira's ConstantsManager service, which manages issue types, statuses, priorities and resolutions | To get all the Resolutions of the instance
|
GroupManager | Returns Jira's GroupManager service, which manages user groups. | To get all the users in a group
|
IssueLinkManager | Returns Jira's IssueLinkManager service, which manages issue links. | To check whether Issue Linking is currently enabled in Jira
|
IssueManager | Returns Jira's IssueManager service, which, in particular, allows you to load issues from keys. | To get the Issue that has the given key
|
IssueSecurityLevelManager | Returns Jira's IssueSecurityLevelManager service. | To get the different levels of security that the current user can see across all projects.
|
JiraAuthenticationContext | Returns Jira's JiraAuthenticationContext service. The JiraAuthenticationContext is used for tracking a user's session in JIRA and all it's custom parameters, such as Locale and I18n. | To get the logged in user
|
JiraDurationUtils | Returns Jira's JiraDurationUtils service, which is reponsible for printing durations in various formats. | |
ProjectComponentManager | Returns Jira's ProjectComponentManager service, which manages project Components. | To find components by the lead
|
ProjectManager | Returns Jira's ProjectManager service | To get all projects ordered by name:
|
ProjectRoleManager | Returns Jira's ProjectRoleManager service, which allows you to check role membership. | To get project role object by name
|
UserManager | Returns Jira's UserManager service. | To get a user by username
|
UserPropertyManager | Returns Jira's UserPropertyManager service, which gives access to user properties. | To get user property set of the current user
|
UserUtil | Returns Jira's UserUtil service, which provides user management capabilities. | To get a list of Jira Admin users:
|
VersionManager | Returns Jira's VersionManager service, which manages project Versions. | To get all the released versions including archived
|
...