You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
My team did some import for X-RAY and we need to associate tests with preconditions based on the labels.
The only common field is the labels.
The prob is that the precondition field is a custom one that need issue key. we have to specify the issue key to do the association.
I'm not that good in scriptrunner nor groovy.
If someone could help us to script this.
Big thanks
Hi @Oussama Brik ,
I am not sure to understand fully your problem, but here is a groovy script that will return issues with the label "test" :
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.web.bean.PagerFilter
def jqlSearch = "labels = \"test\""
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
def userManager = ComponentAccessor.getUserManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = userManager.getUserByKey('berry_a')
List<Issue> issues = null
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.results.collect {issueManager.getIssueObject(it.id)}
} else {
log.error("Invalid JQL: " + jqlSearch);
}
return issues
Hope that helps
thanks @Antoine Berry I found a way to solve my prob:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def GetIssueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("com.acme.workflows")
log.setLevel(Level.DEBUG)
final customFieldName = "customfield_12345"
def IssueCF = customFieldManager.getCustomFieldObject(customFieldName)
def query1 = jqlQueryParser.parseQuery('project = MyProject AND (type = bug) AND (labels is not Empty) ')
def results1 = searchProvider.search(query1, user, PagerFilter.getUnlimitedFilter())
def List1 = results1.issues.collect{issueManager.getIssueByCurrentKey(it.key)}
def query2 = jqlQueryParser.parseQuery('project = MyProject AND (type = task) AND (labels is not Empty)')
def Results2 = searchProvider.search(query2, user, PagerFilter.getUnlimitedFilter())
def List2 = Results2.issues.collect{issueManager.getIssueByCurrentKey(it.key)}
Results2.getIssues().each { documentIssue ->
def Issue2Key = documentIssue.key
def Label2 = documentIssue.labels
String Label2_String = Label2.first()
results1.getIssues().each { documentIssue2 ->
def Issue1Key = documentIssue2.key
def Issue1Object = issueManager.getIssueObject(Issue1Key)
def Issue1Label = documentIssue2.labels
String Label1_String = Issue1Label.first()
def Issue1CF = documentIssue2.getCustomFieldValue(IssueCF)
if(Label1_String.equals(Label2_String) && !Issue1CF){
Issue1Object.setCustomFieldValue(IssueCF, [Issue2Key])
GetIssueManager.updateIssue(user, Issue1Object, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.