如何用JQL和Adaptavist ScriptRunner查询ABC项目下关联问题全关闭的Jira史诗?
Alright, let's tackle these two Jira scenarios with practical, actionable solutions—no fluff, just what you need to get the job done.
Native JQL doesn’t have a direct operator to check if all linked issues are closed, but we can work around this with a straightforward two-step approach:
First, create a filter to catch all unresolved issues in your instance (adjust status names to match your Jira setup):
status != Closed AND status != DoneSave this filter with a clear name like "Unresolved Issues"—you’ll reference it in the next step.
Second, use this filter to exclude epics that have any unresolved linked issues. The final JQL will leave you with only epics where every linked issue is closed:
type = Epic AND issue NOT IN epicIssues(filter = "Unresolved Issues")If you prefer to skip creating a filter, you can nest the JQL directly (note: some older Jira versions may have trouble with nested
epicIssues()calls):type = Epic AND issue NOT IN epicIssues(status != Closed AND status != Done)
ScriptRunner unlocks more direct, flexible ways to handle this—here are two solid options tailored to your project:
Option 1: Use ScriptRunner’s Built-in JQL Function
ScriptRunner has a built-in epicIssuesMatch() function that lets you check if any linked issues match a condition. We’ll invert this logic to exclude epics with unresolved issues:
project = ABC AND type = Epic AND NOT epicIssuesMatch("status != Closed")
Quick Notes:
- Replace
Closedwith your actual closed status (e.g.,Done,Resolved) if your team uses different terminology. - For Jira Cloud, ScriptRunner offers a more explicit function:
epicHasAllIssuesInStatus(). Use it like this for cleaner syntax:project = ABC AND type = Epic AND epicHasAllIssuesInStatus("Closed")
Option 2: Custom Scripted JQL Function (For Full Control)
If you need to add custom logic (e.g., exclude sub-tasks, check multiple statuses), create a custom ScriptRunner function:
- In ScriptRunner, navigate to Scripted JQL Functions and create a new function named
allEpicIssuesClosed. - Paste this Groovy script (adjust the status list to match your Jira’s closed states):
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def issueManager = ComponentAccessor.getIssueManager() def epicLinkManager = ComponentAccessor.getComponent("com.atlassian.jira.issue.link.EpicLinkManager") return issues.findAll { Issue epic -> def epicIssues = epicLinkManager.getIssuesInEpic(epic) // Verify all linked issues are in a closed status epicIssues.every { it.status.name in ["Closed", "Done"] } } - Save the function, then use it in your JQL to target project "ABC":
project = ABC AND type = Epic AND issue IN allEpicIssuesClosed()
Important Reminders:
- Ensure you have ScriptRunner permissions and access to the "ABC" project to run these queries.
- Double-check status names—mismatches will break the query’s accuracy.
内容的提问来源于stack exchange,提问作者Max MacLeod

