Forked from matts-mpg/get-jira-issue-matchstuff.groovy
Created
October 21, 2022 12:19
-
-
Save mateuszszulc/668014f1a9256c8043b05d499579995b to your computer and use it in GitHub Desktop.
This script should work with scriptrunner in JIRA to a) get an issue; b) match some stuff in the description; and c) get values from custom fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Import classes you need | |
import com.atlassian.jira.ComponentAccessor; | |
import com.atlassian.jira.issue.Issue; | |
import com.atlassian.jira.issue.CustomFieldManager; | |
import com.atlassian.jira.issue.MutableIssue; | |
import com.atlassian.jira.issue.IssueManager; | |
import com.atlassian.jira.component.ComponentAccessor; | |
import com.atlassian.jira.user.ApplicationUser; | |
import com.atlassian.jira.security.JiraAuthenticationContext; | |
import com.atlassian.jira.issue.fields.CustomField; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
// Get some additional information you typically need like current user | |
JiraAuthenticationContext userMgr = ComponentAccessor.getJiraAuthenticationContext(); | |
ApplicationUser currentUserObj = userMgr.getLoggedInUser(); | |
//Get an IssueManager. you always need one of those. | |
IssueManager issueMgr = ComponentAccessor.getIssueManager(); | |
CustomFieldManager fieldmgr = ComponentAccessor.getCustomFieldManager(); | |
MutableIssue issue = issueMgr.getIssueObject("JRA-132") // this is just an example key | |
//Create the regex matcher(s) you need | |
def matcher = issue.description =~ /INC\d\d\d\d\d/ | |
try { | |
String res = matcher[0] | |
log.error "Component matcher found " + res; | |
} catch ( IndexOutOfBoundsException e ) { | |
log.error e; | |
} | |
//Print stuff. Just assuming you are playing around/learning in the Scriptrunner console. | |
log.error ""; | |
log.error "The current user is " + currentUserObj.name; | |
log.error "The current issue ID is " + issue.id; | |
log.error "The current issue key is " + issue.key; | |
log.error "The current issue description is " + issue.description; | |
log.error "The current issue special field value is " + issue.getCustomFieldValue(fieldmgr.getCustomFieldObject(10603L)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment