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
...
Step 2 - Write the script in the editor
Write the following script in the editor.
Code Block language groovy linenumbers true if(issue.getAsString("priority") == "Critical" || issue.getAsString("priority") == "Highest"){ return true } else{ return false }
- Your script will look like this:
Step 3 - Test your script
- Click on
Test Groovy Script
. - Input the issue key
GIJ-3
- Click on
Test
- The following result will be displayed.
Step 4 - Simplify your script
You can simplify the script removing the if-else
and returning the result of the comparison which is a Groovy truthy or falsy
- Go to the editor
Replace the script with the following code:
Code Block language groovy linenumbers true issue.getAsString("priority") == "Critical" || issue.getAsString("priority") == "Highest"
Step 5 - Retest your script
- Click on
Test again
. - The following result will be displayed.
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 only if the priority of the issue is Critical
or Highest
.
...
- Go to the Administration icon and click on it.
- Go to Issues - > Workflows
- Locate the workflow GIJ: Process Management Workflow
- Edit it
- Click on transition Start Progress
- Go to the
Conditions
tab - Edit the first condition in the list.
Step 2 - Write the script in the condition
Write the following script in
Groovy script
.Code Block language groovy linenumbers true issue.get("assignee") == currentUser
- Your configuration should look like this:
Step 3 - Test your script
- Click on
Test Groovy Script
. - Input the issue key
GIJ-5
- Click on
Test
- The following result will be displayed.
Step 4 - Save the configuration
- Click on
Update
- Publish the workflow (you dont need to save a backup copy).
Step 5 - Test it on an issue
- View the issue
GIJ-5
in a new tab. - Check that the transition
Start Progress
is not available for a trigger on the issueGIJ-5.
- Click on
Assign to me
, to assign it to the logged in user.
- Check that the transition
Start Progress
is now available for a trigger on the issueGIJ-5.
Use cases
The output of the code is a Boolean. You can use this script in any relevant context, such as
- Allowing progress on an issue only if the issue is assigned to the logged in user
- Allowing only the reporter of the issue to close the issue
...
- Go back to the previous tab.
- Edit the workflow in
Diagram
mode. - Click on the Create transition
- Click on Post-functions
- Edit the second post-function in the list.
Step 2 - Write the script in the post-function
Write the following script in
Value.
Code Block language groovy linenumbers true def component = issue.getAsString("components") def priority = "" switch (component) { case "Finance" : priority = "Highest"; break case "Production Planning" || "Quality Management" : priority = "High"; break default : priority = "Medium"; break }
- Your script should look like this:
Step 3 - Test your script
- Click on
Test Groovy Script
. - Input the issue key
GIJ-5
- Click on
Test
- The following result will be displayed.
Use cases
The output of the code is a String representing the priority of an issue. You can use this script in any relevant context, such as, setting the priority of the issue to based on the Component/s.
...