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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Groovy script Regex Matcher issue

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 04, 2019

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

Suggest an answer

Log in or Sign up to 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

TAGS
AUG Leaders

Atlassian Community Events