Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

75 views 0 4
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