Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,366,316
Community Members
 
Community Events
168
Community Groups

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

Atlassian Community Events