JQL to retrieve all stories and sub tasks related to specific epic
Asked Answered
K

7

11

Is it possible to use raw JQL (not using any plugins) to filter for ALL stories AND their respective sub-tasks?

Currently, I have the following which successfully retrieves all stories for EPIC-123:

project = PROJ1 AND "Epic Link" = EPIC-123 AND issuetype = Story ORDER BY priority DESC, updated DESC

However, I also want the sub-tasks related to those stories. So I thought this would work:

project = PROJ1 AND "Epic Link" = EPIC-123 AND (issuetype = Story OR issuetype = Sub-task) ORDER BY priority DESC, updated DESC

But this only returns the stories.

I think this is because JIRA reads this as "Retrieve sub-tasks for EPIC-123" (which is 0) as opposed to "Retrieve sub-tasks for stories in EPIC-123".

I also thought about using issue in (linkedIssues(AAA-###)) but I imagine this will involve programatically looping through all the stories that are returned in the above query. Which seems ridiculous and probably not possible.

Would rather not go down a plugin path but open to suggestions. Thanks!

Kraska answered 8/2, 2016 at 10:54 Comment(10)
You can filter either parent issues or sub tasks. So you can get parent issues which have sub tasks meeting certain criteria, or you can get sub tasks whose parent issues meet certain criteria. For example there is function "issueFunction in subtasksOf..." which will return sub tasks based on parent task data .. and it is part of Script Runner plugin.Drudgery
@Drudgery Sounds good, not sure how to put that in JQL though. Could you provide some example JQL please?Kraska
Also, been tinkering with the idea of just assigning everything to a label and doing project = "PROJ1" AND labels = label-123 ORDER BY priority DESC, updated DESC . Any negative repercussions to that?Kraska
I don't recommend labels as they are very informal and user can change them, create new etc... For issues that have Epic you can do: issueFunction in linkedIssuesOf("", "has Epic") with optional subquery as a first parameter. Or the other way around as: issuefunction in linkedIssuesOf("", "is Epic of"). For subtasks you could use the functions above. I'm not sure what exactly you're trying to do, can you be more specific? You can't have tree relationship as an output of JQL so you have to separate it into multiple queries.Drudgery
@Drudgery I basically want to be able to branch off entire Epics and it's respective stories/sub-tasks to a completely new board. This is to separate Client A from Client B from viewing unrelated stories/tasks.Kraska
Then you can use this: issueFunction in linkedIssuesOf("subquery", "has Epic") and the subquery would specify epics you're interested in. That will give you relevant issues that belong to that epic. You need to distinguish epics somehow based on clients.Drudgery
@robert I can distinguish epics/clients fine. Is issueFunction part of the standard JQL? I am seeing this error now Field 'issueFunction' does not exist or you do not have permission to view it.Kraska
No it's part of Script Runner plugin (there is also free version)Drudgery
Let us continue this discussion in chat.Kraska
@Kraska were you able to find a solution for this? facing exact issue here for same scenarioHellbent
O
5

As of 13 January 2017, Jira Cloud support parentEpic that does exactly what you are asking for. You can use it like:

parentEpic = EPIC-123

and this will find the EPIC-123 itself, plus all the issues assigned to the epic and their sub-tasks.

Oney answered 27/8, 2018 at 11:27 Comment(1)
doesn't work, only shows the epic ticket itselfBane
E
5

This worked for me.

"Epic Link" = JIRA-123 or Parent in ("JIRA-123")
Emad answered 23/12, 2021 at 15:4 Comment(2)
In 2022 the first part of this is the only answer that worked for me. ("Parent in" did not work) I discovered this by going to Reports -> Epic Report -> "View in Issue Navigator", which automatically takes you to the JQL with the above ("Epic Link").Canning
Works for me on Jira v9.4.10Haemolysin
A
3

parentEpic wasn't working for me, but I figured this out using childIssuesOf! I hope this helps someone still looking for an answer on this:

"Epic Link" = EPIC-123 OR parent in childIssuesOf("EPIC-123")

The first half of the query gets all the Stories, Tasks, and Bugs of the Epic, and the second half of the query gets you all the subtasks of the Epic.

Annis answered 13/1, 2023 at 13:31 Comment(0)
L
0

The function issuesWhereEpicIn() is available as of v5.2:

issue in issuesWhereEpicIn("issue = JIRA-1234”)
OR
parent in issuesWhereEpicIn("issue = JIRA-1234")
Lieutenant answered 9/2, 2016 at 20:59 Comment(1)
Forgot to mention I'm using Jira cloud. If the above is part of the JQL tricks plug in then I can't install that onto the cloud version.Kraska
S
0

You can query all stories/tasks/subtasks/defects/etc, related to EPIC-123 plus that epic itself using the following JQL:

parentEpic IN (EPIC-123)

You can have multiple Epics in the query:

parentEpic IN (EPIC-123, EPIC-456)
Sturgill answered 3/8, 2021 at 10:32 Comment(0)
K
0

I use:

parentEpic = AB-12345

or:

parentEpic in (AB-12345, AB-67890)
Kisser answered 27/10, 2021 at 10:50 Comment(0)
H
0

Basically, you need to include issues with empty "Epic Link" property. So correct JQL for your ask is:

project = PROJ1 AND ("Epic Link" = EPIC-123 OR "Epic Link" is EMPTY) AND (issuetype = Story OR issuetype = Sub-task) ORDER BY priority DESC, updated DESC

Brief explanation: sub-tasks doesn't have epic links so when you specifies AND condition with "Epic Link" it filters out any issues that doesn't have this field(haven't found anything in JQL doc related to this but it works).

Honshu answered 28/1 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.