Versions Compared

Key

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


Excerpt

This tutorial will guide you through writing simple and complex Groovy conditions. The result of a scripted condition is a boolean. It can be used either to control the execution of a post-function or availability of a transition or trigger of a transition.

...

Step 2 - Write the script in the editor

  1. Write the following script in the editor.

    Code Block
    languagegroovy
    linenumberstrue
    if(issue.get("priority").getName() == "Critical"){
      return true
    }
    else{
      return false
    }


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. 
  5. Image Modified

Step 4 - Simplify your script

You can simplify the script removing the if-else and returning the result of the comparision, a Groovy truthy or falsy

  1. Go the editor
  2. Replace the script to:

    Code Block
    languagegroovy
    linenumberstrue
    issue.get("priority").getName() == "Critical"


Step 5 - Retest your script

  1. Click on Test again.
  2. The following result will be displayed. 
  3. Image Modified

Use cases

The output of the code is a boolean value. You can use this script in any relevant context, such as, Assign the issue to the Project lead if the priority of the issue is Critical.

...

2.2 Condition

...

comparing two objects

This section of the tutorial will teach you condition to compare two ApplicationUser objects.

...

  1. Go to the Administration icon  and click on it.
  2. Go to Issues - > Workflows
  3. Locate the workflow Software Simplified Workflow for Project GIJ
  4. Edit it
  5. Click on transition Start Progress
  6. Go to the Conditions tab
  7. Edit the first condition in the list.

Step 2 - Write the script in the condition

  1. Write the following script in Value.


    Code Block
    languagegroovy
    linenumberstrue
    issue.get("assignee") == currentUser


  2. Your condition should look like this:
  3. Image Modified

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.
  5. Image Modified
  6. Click on Update and save the condition.

Use cases

The output of the code is a boolean. You can use this script in any other relevant context, such as

  • Allow progress on an issue only if the issue is assigned to the logged in user
  • Only the reporter of the issue should be able to close the issue

...

  1. Go to the Administration icon  and click on it.
  2. Go to Issues - > Workflows
  3. Locate the workflow Software Simplified Workflow for Project GIJ
  4. Edit it
  5. Click on the Create transition
  6. Go to the Post-functions tab
  7. Edit the last post-function in the list.

Step 2 - Write the script in the post-function

  1. Select Groovy expression as the Transition type.

  2. Write the following script in Transition.


    Code Block
    languagegroovy
    linenumberstrue
    if (issu


  3. Your script should look like this:

...