Conditional execution/validation using a Groovy expression
The Post functions and Validators provided by the JMWE add-on have a Conditional execution/Conditional Validation
section to control the execution of the post-function/validator respectively. You need to provide a Groovy script in the editor based on whose result, the post-function/validator will either be executed or skipped.
On this page:
Conditional execution of a post-function
To conditionally execute a post-function, select Only if condition is true option in the Conditional execution section of the post-function and add a Groovy expression in the Condition. The post-function is executed only if the written condition evaluates to true or a Groovy truthy. In post-functions that operate on related Issues (like Transition related issues, Set field value of related issues, etc.) the conditional execution script runs once for each related issue, and the related issue is available through the relatedIssue
variable and the deprecated linkedIssue
variable in your Groovy script.
Conditional validation
To conditionally execute a validator, select Conditional validation option in the Validator scope section of the validator and add a Groovy expression in the Condition. The validator is executed only if the written condition evaluates to true or a Groovy truthy. In validators that operate on related Issues (like Related Issues Validator etc.), the conditional execution script runs once for each related issue, and the related issue is available through the relatedIssue
variable and the deprecated linkedIssue
variable in your Groovy script.
Expected Value for a condition
The value should be either a boolean value (true
or false
), or more generally any value that will be interpreted as either "truthy" or "falsy". Click on the Expected Value tab of the Groovy editor to know the expected value. You can also quickly test your written script against any issue using the script tester tool. For example:
Groovy expressions returning a "truthy" value:
1 == 1
or any boolean expression that istrue
issue.get("assignee")
if the issue is assignedissue.getAsString("assignee") == "jdoe"
if the issue is assigned to user "jdoe"issue.get("description")
if the issue's description is not empty
Groovy expressions returning a "falsy" value:
Any value will be interpreted as "falsy" (the equivalent of false
) except: true, a non-empty string, a non-empty Collection, a non-empty Map, a non-empty array, a number different from zero (0
)
For example, false, 0, "", []
Below are a few use cases that detail the usage of these functionalities.
Use cases
Conditional execution
Automatically escalate an issue if it is being raised with a "Blocker" priority.
Auto-assign a created issue to the Product owner, only if the issue is a Bug
Add a comment on the Epic when its user stories of a client-side project are resolved.
Conditional validation
Allow the members of the Managers
project role to omit the comment
Force the user to provide a Fix Version/s on resolving a bug, only when the resolution is "Fixed"