Is there a way to write JQL with passed in parameters?

Mark Lang
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.
April 29, 2016

I know JIRA doesn't have variables in JQL filters, but I was wondering if you could ask the Atlassian support for best practices on how to work around this limitation.

 

To give you more details, due to the integration with CDETS and with CCO Bug search, we need to update our release notes dashboards with filters that look like:

 

"Release note as open" not in ("1.1(1)") and fixVersion not in ("1.1(1)") and "Exclude from release notes" not in ("1.1(1)")

[this means the bug is "undecided" for release "1.1(1)"]

 

This has to happen for every maintenance release, and we have 4 to 5 different filters that look more or less like that one for each maintenance release.

So overall we're looking at adding 5 more filters (and a corresponding dashboard) every 6 weeks (the cadence of maintenance releases), all exactly identical except for the version label in there. And we can't drop any of them because we need to continue to release notes bugs (at least open bugs) in each maintenance release long after the release ships.

 

What would be ideal (and can't be done in JIRA) is:

 

Filter(x) = "Release note as open" not in ({x}) and fixVersion not in ({x}) and "Exclude from release notes" not in ({x})

 

I'm wondering if Atlassian support can suggest some compromise in between the "ideal" above and the harsh reality of cloning 5 filters and manually editing out the same label 3 times in each filter (very error prone, besides being very tedious).

 

Note that we can script the creation of the filters, but that does not address the other issue: with one maintenance release every 6 weeks and 5 filters per maintenance release, in a year we'll have 44 new filters to nurture.

2 answers

1 vote
JamieA
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.
May 2, 2016

You tagged with the ScriptRunner tag although it seems like you don't want a scripting answer, as you already know how to create queries programatically, which is most of the battle.

You could create a JQL function called something like releaseNotesFor(1.0), which would in effect just run the query you have as an example, but I don't see that it would be that helpful because you would still need 5 queries, by the sounds of things.

I think you should forget about the queries to some extent, and focus on programatically building your dashboard or confluence page or whatever, and treat the queries as ephemeral.

 

Mark Lang
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.
May 2, 2016

I tagged with ScriptRunner because i have found a lot of your built in functions to be extremely useful and very close to being able to parameterize.  

You are correct that it should be to focus on programmatically building the dashboard or confluence page but how can the data that drives that programmatic approach be pulled and then turned around to be used to get the actual data that is wanted for said dashboard/page?  Are you suggesting REST services or some other means?   

JamieA
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.
May 3, 2016

Not really sure I understand what you mean. The data is got by the generated queries, which are used in dashboards or whatever.

What is the actual pain point here, to me it sounds like creating the 5 queries, then plugging them into a dashboard?

Mark Lang
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.
May 4, 2016

I was reacting to "but I don't see that it would be that helpful because you would still need 5 queries, by the sounds of things" and I wasn't focusing on the we could create our own JQL function with a parameter in it.  And I took this to mean that I would still have 5 queries that are getting modified every 6 weeks with the old baggage.  But that isn't the case once we have a custom built JQL function. So I was hoping/expecting information on how to do that.  

It looks like in your old documentation you mention it - https://jamieechlin.atlassian.net/wiki/pages/viewpage.action?pageId=57999378#ScriptedJQLFunctions-Writingyourownfunctions but I haven't found the same documentation in the new page https://scriptrunner.adaptavist.com/latest/jira/ unless it is the https://scriptrunner.adaptavist.com/latest/jira/creating-a-script-plugin.html or I go back to Atlassian documentation at https://developer.atlassian.com/jiradev/jira-platform/guides/search/tutorial-adding-a-jql-function-to-jira.  

JamieA
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.
May 6, 2016

I have written up how to create a JQL alias function here: https://scriptrunner.adaptavist.com/4.3.1-SNAPSHOT/jira/custom-jql-functions.html - which also replaces the old docn you found above.

I may write some sample code on generating dashboards soon. Interested in any feedback as always.



Like jim.rice.us likes this
Marco Di Benedetto May 9, 2016

Jamie,

     thanks for the writeup. One question: with JIRA v7.0.10 and Scriptrunner 4.2.0.4, it looks like inline scripts are only possible for "Script console", "Script Fields" and for "Script Listeners". As far as I can tell, inline scripts are not possible for "Script JQL Functions". Is that true or am I missing something? And is that just a roadmap item, or are there technical reasons to never expose "Script JQL Functions" inline? (I see there's a released 4.3.0 which is not installed on my JIRA instance).

I manage a JIRA instance (jira-administrators) but I don't have access to the JIRA VM console/ssh, so the only way to get to "Script JQL Functions" would be to manage them from within the JIRA Add-ons management page (not from the VM file system).

 

Jozef Kotlár
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.
May 9, 2016

@Marco Di Benedetto - with Scriptrunner console you can do everything, the user running JIRA application can do. So even unpack TAR attached to some issue wink. See this snippet,

JamieA
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.
May 9, 2016

Yeah... Marco you are correct, there is not a text area. Jozef is also correct, you can write to the file system from a simple script, eg fetch the actual code from a url and write under the script root. But test on a test instance where you can get to the file system so you can see how it works.

0 votes
Jozef Kotlár
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.
May 1, 2016

I am not aware of such solution, but you are probably looking for something like this add-on using metadata as store for value returned by JQL.

If you can handle properly release dates - you can probably cover your use case with earliestUnreleasedVersion()

dang hieu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 27, 2020

@Mark Lang 

" I'm wondering if Atlassian support can suggest some compromise in between the "ideal" above and the harsh reality of cloning 5 filters and manually editing out the same label 3 times in each filter (very error prone, besides being very tedious)"

I have the exact same need for the versions filters, did you come up with an easy way to display them ?

thanks in advance 

Like Deleted user likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events