Is there a way to use variables in JQL?

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

I would like to create a set of queries for a dashboard that I can re-use from version to version such that I can use a variable in the JQL.  This would allow me to make a single change which would affect all the filters used on that dashboard.  The only other option is to manually edit every bloody filter.

3 answers

1 accepted

7 votes
Answer accepted
Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 16, 2015

I would have suggested using ScriptRunner to programatically update the JQL queries. I've done this before and it worked well, it's not particularly difficult. But you discounted that plugin, so I have another suggestion.

Create a shared filter named FixVersionFilter as:

fixVersion = 'big branch' and status = Open

Then you create your project filters as:

project = dookie and filter = FixVersionFilter

Then when you change FixVersionFilter it will affect the results of the project-specific filters.

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2015

That looks like it would work! I had no idea you could filter on a filter. Where's Xzibit when you need him?

Like # people like this
carlosbuz2 March 13, 2018

Works! Thx!

Jamie Echlin _ScriptRunner - The Adaptavist Group_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 8, 2018

Since I wrote the above we added a section to our documentation on dumping and programatically creating dashboards and gadgets: https://scriptrunner.adaptavist.com/latest/jira/recipes/dashboard-gadgets.html

Like Rob Horan likes this
Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 15, 2021

The only problem with that approach is the ScriptRunner requirement, which has been prohibitively expensive for several teams I've worked with, especially given the steep learning curve.

1 vote
GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

I usually use the "fixed" statements like "startOfWeek()" "startOfMonth()" etc... so the values are not static and updates automatically, that's the closest you can get with this I think. Since filters in the dashboard is dependent with Gadgets, this will make your feature request tricky. Where to put those variables then? You can send a request to Atlassian and see what they think about it. There maybe an add-on for it or a gadget add-on though...

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

I probably will enter or vote on a request, but let's be realistic. Atlassian still hasn't implemented WYSIWYG, the ability to rename groups, subcomponents, etc... some of these request are teenagers. By the time my request gets done I'll likely be retired. The pre-fab variables are OK for some things, but they don't help. We work on multiple versions simultaneously, along separate branches. I need a variable per branch to show the current state of the branch. I would use something like: project = dookie and fixVersion = "big branch" and status = Open We don't actually have a dookie project, btw

GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

We are in the same situation. We have a dashboard per major release that needs to be manually recreated each time.

0 votes
Nicolas Bourdages
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

You can't use variables out of the box, no.

Scriptrunner allows you to use additional JQL functions or to make your own. For instance, you could create your own latestUnreleasedVersion() function that would always return, hum, the latest unreleased version.

Check out the documentation.

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

I'm hesitant to use ScriptRunner now that they have moved to a pay model.

Nicolas Bourdages
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

Yeah, but to be honest, that plugin was way too good to be free. It's really worth the cost, especially the regex match functions (componentMatch, projectMatch)

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

Perhaps, but even so, I'm likely not going to get additional funding for paid plugins. Using it could mean we would never be able to go past Jira 6.

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

The other thing is I would need to teach myself how to use it from the ground up. I can't really justify asking for funds for a plugin I cannot use.

Nicolas Bourdages
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2015

I hear you. I always have hard choices to do with limited budgets too. I really doubt you'll be able to fix your filter issue for free. Creating your own plugin is possible of course, but unless you're already pretty good at it, there's no way this is cost-effective.

Suggest an answer

Log in or Sign up to answer