Finally, figured it out! You can find issues that have only one label and the label is "Foo", and also exclude any other labels with the following query:
project = YourProjectName AND
labels = Foo AND
issueFunction IN issueFieldMatch("project = YourProjectName", labels, "^[^,]*$")
Just replace YourProjectName with your actual project name.
This JQL query works in the following way:
project = YourProjectName AND labels = Foo
This part of the query returns all issues in your project that have the "Foo" label.
issueFunction in issueFieldMatch("project = YourProjectName", labels, "^[^,]*$")
This part of the query uses the ScriptRunner JQL function issueFieldMatch to look at all issues in your project and return only those where the labels field matches the regular expression ^[^,]*$
. This regular expression matches strings that do not have a comma, so it will return only those issues that have exactly one label.
Please note that issueFieldMatch is part of ScriptRunner, a third-party app for JIRA developed by Adaptavist. If you do not have ScriptRunner installed, you may not be able to use this query exactly as it is.
^Foo$
and be done with it? But I'll look into ScriptTunner, thanks. – Principality