Versions Compared

Key

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

You can prevent the Jira issue from transition to the next state if not all Smart Checklist items are checked.

...

  1. Go to Workflows

  2. Choose one that you want to add validation to and click Edit

  3. Choose transition and click on "Validators" link

  4. Add Validator

  5. Choose "Smart Checklist Completed Validator"

  6. Click Add - new Validator will be saved

  7. Then Publish this changed workflow

...

Using Scripted (Groovy) Validator you can check if all items with the text 'Code reviewed' and 'Unit tests are written and passing' are done:

Code Block
def checklist = issue.get("customfield_10113");import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject("customfield_10201")
if (!customField) {
    log.warn("Custom field with ID 'customfield_10201' not found!")
    return true
}
def checklist = issue.getCustomFieldValue(customField) as String
if (!checklist || checklist.trim().isEmpty()) {
    return true;
}
def checklistItems = checklist.split('"\\n'")*.toString().findAll({ it -> it.matches("^[-|+|~].*")});
for (String item in checklistItems) {
    if (!item.startsWith("+") && (item.contains("Code reviewed") || item.contains("Unit tests written and passing"))) {
	return false;
        throw new InvalidInputException("Checklist validation failed: '${item}' is not completed.")
    }
}
return true;

...

Using Custom Script Validator in ScriptRunner

To implement this validation using Custom Script Validator, follow these steps:

  1. Navigate to Jira Administration > Issues > Workflows, edit the relevant workflow, and select the transition where the validation should be applied.

  2. In the transition settings, go to the Validators tab and add a Custom Scripted Validator.

  3. Insert the script above into the script field, ensuring to replace customfield_10201 with your actual field ID.

  4. Customize the checklist items: The script currently checks for the items 'Code reviewed' and 'Unit tests written and passing' as an example. You should replace these values with the specific checklist items relevant to your workflow.

  5. Save the validator and publish the workflow changes.

Once added, this validator will check if the required checklist items are completed before allowing the issue to transition. If any of the specified items (e.g., 'Code reviewed' or 'Unit tests written and passing') are not marked as done, the transition will be blocked, and an error message will be shown to the user.

Fixing slow Issue transition with validation enabled

Info

The following information could be helpful if the checklist validation is noticeably slowing down the issue Issue transition.

The validations are essentially based on the following query:

...

Update statistics

In order to assure the performance of that query, the database administrator needs to be sure that correct statistics are present in the database. This can be done with the following SQLs:

...