Regex Validator on FixVersion

Hello to all Groovy/query wizards,

I'm looking to have a validator on a Jira transition that checks FixVersion matches a specific regex. (in my case 'digit dot digit digit', ie 3.12 or 6.38).

As I have a previous validator that previously checks that there is exactly one fixversion, we can assume only 1 fixversion is present.

All help is greatly appreciated!

2 answers

1 accepted

This widget could not be displayed.

What you want is to have the validation run when the Version object is created though, no? There's not much point in not letting people pick an existing fix version...

Which is more tricky.

Something like this:

import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException

Issue issue = issue
def fixVersions = issue.fixVersions

if (! fixVersions)
    return

def fixVersion = fixVersions.first()
if (! (fixVersion ==~ /\d\.\d{2}/)) {
    throw new InvalidInputException("fixVersions", "Choose a better fix version")
}

But it depends what version of script runner you are using, you might need a slightly different return type for older versions.

Jamie, thanks for your response.

To clarify: within my project i have a lot of versions functioning as 'shelves' for multiple issues before actual integration into the release codebase. upon moving to the actual release branche (we use a corresponding Jira status for that) these 'shelves' are no longer valid and so the FixVersion is required to have a release like format. You can assume the Fixversions required i.e. 3.12 or 6.38 are already present, so the trickyness is reduced.

For example: in status non-merged an issue still holds FixVersion = 'ShelveVersion1', upon the transition to status MergedInCodeBase I need to check whether it holds a X.XX format.

I hope this clarifies things and that you - as groovy guru - can further my dilemma.

ok I updated my answer

Works like a charm. thank you

This widget could not be displayed.

For me this Simple Scripted Validator works fine:

import com.atlassian.jira.project.version.Version;
def versions = issue.getFixVersions() as List<Version>
issue.getResolutionObject().getName() != "Fixed" || versions.any {it.getName().matches(/(^V\d+\.\d+$)|(^0.\d+.0.\d+$)/)}

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

286 views 5 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you