|
The Groovy script tester in JMCF is available on the Custom field configuration screen when you write a Groovy script
to return a value expected by the calculated custom field in the Groovy Formula field.
After 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.
After selecting issue 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 returns the sum of two number fields:
|
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 encountering the error,
Message
that displayed a null pointer exception error and the Stack
that displayed the line number on which the error occurred.Correct the problem, checking for null values and then returning the result.
In the Groovy editor, write the following lines of code:
if (issue.get("customfield_10028") == null || issue.get("customfield_10006") == null) return null; else return issue.get("customfield_10028") + issue.get("customfield_10006"); |
Test again
.The following result is displayed:
Using the log variable, you can debug your script, a step further, by adding information into the log. For example, while testing a condition in your script, 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. |
Use log variable, in the above script to know the values of the custom fields.
log.warn("Value of field 10028 is: "+issue.get("customfield_10028")); log.warn("Value of field 10006 is: "+issue.get("customfield_10006")); if (issue.get("customfield_10028") == null || issue.get("customfield_10006") == null) return null; else return issue.get("customfield_10028") + issue.get("customfield_10006"); |
Re-test the script, the following result is displayed.
Remove your logging code, so that log entries don't get written to Jira's logfile each time the field is calculated.