I have a label in Jira, say Foo
. I want to query for all issues that have that label and that label only. How do I do that?
I've tried
labels = Foo AND NOT(labels NOT IN (Foo))
but that returns issues labelled Foo
and Bar
as well. I want the issues labelled only Foo
.
How do I query for issues in Jira that have a specific label and only that label?
There's no JQL way of doing this that I'm aware of (obviously, hard to prove a negative but I have fairly decent knowledge of JQL).
The obvious approaches don't work:
labels != Foo
does NOT return tickets that have Foo, at all (by design, because !=
is 100% equivalent to NOT ... =
as per documentation), so doing labels != Foo AND labels = Foo
returns empty set.
Can't use text matching ~
or !~
; JIRA will throw JQL errors: The operator '!~' is not supported by 'labels' field
. That's because it's a picker/multiple choice field, not a text one.
The only value you can compare "labels" to using IS/IS NOT
is "EMPTY"
The 2.5 workarounds (that all suck, admittedly) are:
Find the most used "extra" tags, and build a query excluding them
... AND labels = Foo AND labels NOT IN (Bar1, Bar2, ...)
Pros: Pure JQL, simple
Cons: Doesn't catch less-used labels; needs to be updated when more labels are added; and may not scale well if you have super many extra labels that pair with Foo.
Use a macro. This Atlassian Q&A details
labels_count
, using the formula @@Formula: issue.get("labels").size()
AND labels_count = 1
in your JQLPros: Should work
Cons: I didn't actually test it so not sure if it will work. It requires installing a new plugin (a useful one!) and reindexing. And I don't know if it will keep the field updated without further reindexing - I think it would but not 100% certain.
Not sure if this will work, but you can look at another way to create custom fields:
Create a field with Groovy code to return count of labels.
Best as I can tell, something like return issue.getlabels().size()
Some sample code related to ScriptRunner and labels: ex1; ex2
Pros: ???
Cons: Paid plugin, not sure how to get this to work.