Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Using the Groovy Script tester

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. 

...

  • Issue key: start typing an issue key, you will be offered options based on your issue browsing history
  • [Select issue]: if you click on [Select Issue], an Issue selector window gets displayed. You can select the issue either from:
    • Recent Issues: Displays issues that you have recently viewed and first 50 issues from your current search or
    • From Filter: Displays issues of your saved searches.

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.

  1. Message: Success/error message based on the test result.

  2. Result type: Data type of the result.
  3. Result value: Value of the result.
  4. Stack: If an exception was thrown during the execution of the script, a stack trace will be displayed.
  5. Logs: Information logged using the log variable.

...

Panel

Test a script that returns the sum of two number fields:

  1. Locate the custom field on the Custom Fields administration page.
  2. Click on the cog wheel and click on Configure.
  3. In the Groovy editor, write the following lines of code:

    Code Block
    languagegroovy
    linenumberstrue
    issue.get("customfield_10114") + issue.get("customfield_10150")


  4. Click on the Test Groovy Script button on the toolbar.
  5. Type an Issue key.
  6. Click on Test.
  7. The following result is displayed:

...

  • Identify the problem, from the 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:

      Code Block
      languagegroovy
      linenumberstrue
      if (issue.get("customfield_10028") == null || issue.get("customfield_10006") == null)
          return null;
      else  
      return issue.get("customfield_10028") + issue.get("customfield_10006");


    • Click on Test again.

    • The following result is displayed:

...