jirajql

How do I query for issues in JIRA that have a specific label and only that label?


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?


Solution

  • 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:

    The 2.5 workarounds (that all suck, admittedly) are:

    1. 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.

    2. Use a macro. This Atlassian Q&A details

      • Install JIRA Misc Custom Fields plugin
      • Create a custom numeric field labels_count, using the formula @@Formula: issue.get("labels").size()
      • Re-index JIRA
      • Include AND labels_count = 1 in your JQL

      Pros: 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.

    3. Not sure if this will work, but you can look at another way to create custom fields:

      • Use Script Runner plugin

      • 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.