Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy script Regex Matcher issue

We are tying to create a listener on VersionCreate. The listener will check if the version matches a particular pattern and execute some steps.  here is the code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.project.VersionCreateEvent
import java.text.SimpleDateFormat
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import java.util.regex.*

def
customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def project = projectManager.getProjectObjByKey("TESTS")
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(project).find { it.name == "Test Plan" }
def event = event as VersionCreateEvent

// Construct The Pattern to Match on SP
Pattern patternSP = Pattern.compile('SP')
log.warn("Pattern : ${patternSP}")
log.warn("Version Name : ${event.version.name}")
Matcher matcherSP = patternSP.matcher(event.version.name.toString())
log.warn("Matcher : ${matcherSP}")
log.warn("Matching Results : ${matcherSP.find()}")

// Construct The Pattern to Match on HF
Pattern patternHF = Pattern.compile('HF')
log.warn("Pattern : ${patternHF}")
log.warn("Version Name : ${event.version.name}")

Matcher matcherHF = patternHF.matcher(event.version.name.toString())
log.warn("Matcher : ${matcherHF}")
log.warn("Matching Results : ${matcherHF.find()}")

if(matcherSP.find() && !matcherHF.find())
{
log
.warn("SP Release")
}
else if (!matcherSP.find() && !matcherHF.find())
{
log.warn("Major Release")
}
else { log.info "HF will not have any test plans"}

But this always should the message "Major Release" for any value that is entered for the version. Here is what should be displayed:

2019.10 : "Major Release"

2019.10-SP1 : "Service Pack"

2019.10-SP1HF : "HF will not have any test plans"

Is this implementation is correct? Is there an alternate way to implement this logic?

1 answer

hi Krishna, I am also looking for same kind of fix. I need to update the trigger for release version using Regex, for example, Release version = 2020.01.0.1

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across Jira Cloud instance.   📢 Get y...

163 views 7 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you