Writing your first Groovy script

This tutorial will guide you through writing your first Groovy script. 

Let us write a simple Groovy script for the functional use case: Calculate and display the key of the issue.

You can do this by writing a Groovy script in the Groovy Formula section of a Calculated text custom field type, to return a String representing the key of the issue.

On this page:


You need not create a Calculated text custom field type for this. The imported backup has everything in place.

Writing the script

Step 1 - Navigate to the Groovy formula in the field configuration

  1. Go to the Administration icon  and click on it.
  2. Go to Issues - > Custom fields
  3. Locate the custom field Issue Key
  4. Click on the cog wheel and click on Configure.
  5. Click on Edit Groovy Formula.

Step 2 - Write the script

  1. In the editor, click on Issue Fields tab of the Groovy editor.

  2. Select the field "Key" from "Select a field" drop-down

  3. Click on the button with text issue.get("issuekey") under the "Accessing the fields" section
  4. The following code gets inserted into the Groovy editor

    issue.get("issuekey")

  5. Your custom field configuration should look like this:

Step 3 - Test your script

  1. Click on Test Groovy Script.
  2. Input the issue key GIJ-1
  3. Click on Test
  4. The following result will be displayed.

Step 4 -  View the custom field value on the issue view

  1. Save the formula.
  2. Perform a re-index as suggested by Jira
  3. Go to the issue 
  4. Verify that the field Key displays the key of the issue.

References