|
The Groovy script tester in JMWE is available on the:
The Groovy script editor in JMWE is available on the:
Groovy expression/Groovy Template
as Value type in the post-functions that set a field valueGroovy expression/Groovy Template
as Comment type in the post-functions that comment an issueCalculated
as ProjectCalculated
as Parent issueSet field value from Groovy
or Set field value from Groovy template
while setting a field in Set fields of new issueGroovy expression/Groovy Template
as Comment type while adding a comment to the current issueAfter writing your Groovy script in the editor, click on the Test Groovy Script
button on the toolbar.
A modal dialog window opens, asking you to pick an issue to run the Groovy script against, as well as a linked issue, where applicable.
You can select the issue from one of the following options:
[Select Issue]
, an Issue selector window gets displayed. You can select the issue either from:The issue
variable used in your script will point to the above-selected issue.
In post-functions that process linked issues after you select an issue (as explained above), all issues linked to it through the link type selected in Issue link
are displayed under Linked issue key
. The linkedIssue
variable used in your script will point to the linked issue you select.
In the post-functions that process the parent issue, after you select an issue (as explained above), its parent is displayed under Parent issue key
. The parentIssue
variable used in your script will point to the parent issue you select.
After selecting issue(s) against which the script should be tested (as explained above), click on Test.
The following information will be displayed. This information can be used for debugging.
Message: Success/error message based on the test result.
log
variable.Example
Test a script that fetches the username of the user the issue is assigned to:
|
If you encounter an error during testing, you will need to debug your script. The Message, Stack and Log information displayed in the script tester result panel aids in debugging the script.
In the above example, after testing the script against an issue that is unassigned:
Message
that displayed a null pointer exception error and the Stack
that displayed the line number on which the error occurred.Correct the problem, using the safe navigation operator ? that avoids the null pointer exception.
return (issue.get("assignee")?.getName()) |
Using the log variable, you can debug your script, a step further, by adding information into the log. For example, while testing a condition, if the result evaluates to false
when you expect it to be true
, you might want to know what values are being compared in your condition. In such cases, you can use the log variable to display the value.
The log calls should always be used before the return statement because they would never get executed after it. |
Consider the following script,
return (issue.get("assignee")? == "Scharlie") |
Scharlie.
The script test would evaluate to false
.Identify the problem, using the log variable (as shown below) and check what values are being compared.
log.warn("Fetched user is" + " " + issue?.get("assignee")) return (issue?.get("assignee") == "Scharlie") |
Retest the script, as explained above and verify the result in the script test panel.
The script is comparing a user object to a String value.
Correct the problem, by fetching the username and then comparing the values
log.warn("Fetched user is" + " " + issue?.get("assignee")) return (issue?.get("assignee").getName() == "Scharlie") |