Jira Automation - Get the next unreleased version by criteria

Boldizsár Vermes November 28, 2022

I like to set the Fix version of issues when they get the Done status to the next unreleased version by release date but not all the releases in the project should be considered.

I tried to iterate through all the releases, filter out archived, released and other releases by name that I don't want to be evaluated to find the next unreleased version. But a failed to continue from here. Any help would be very welcome.

First, I tried to build a JSON array with the following steps:

  1. Created a variable with the following value:
    {{#project.versions}}
    {{#not(archived)}}
    {{#not(released)}}
    {{#if(name.startsWith("Version "))}}
    {{#if(exists(releaseDate))}}
    {"name": {{name.asJsonString}}, "releaseDate": {{releaseDate.jiraDate.asJsonString}}},
    {{/}}
    {{/}}
    {{/}}
    {{/}}
    {{/}}
  2. Created another variable to make a JSON array:
    [{{firstVariable.substringBeforeLast(",").split(",")}}]
  3. Although, this seems to be a valid JSON array, like:
    [{"name": "Version 2022.Q4", "releaseDate": "2022-12-31"}, {"name": "Version 2023.Q1", "releaseDate": "2023-03-31"}]

    I cannot access to its content, the following try does not result in any value:
    {{secondVariable.releaseDate.min}}

 

Then, I tried to get the releaseDate of the release meeting the above-detailed criteria:

  1. Created a variable to list the releaseDates:
    {{#project.versions}}
    {{#not(archived)}}
    {{#not(released)}}
    {{#if(name.startsWith("Version "))}}
    {{#if(exists(releaseDate))}}
    {{releaseDate}},
    {{/}}
    {{/}}
    {{/}}
    {{/}}
    {{/}}
  2. Created another variable to have a real list of the values:
    {{firstVariable.substringBeforeLast(",").split(",")}}
  3. Although, this seems to be a valid list, like:
    2022-12-30T00:00:00.0+0000, 2023-03-31T00:00:00.0+0000
    I cannot select the earliest date, the following results in no value, so I cannot use it to filter for release name by the date:
    {{secondVariable.min}}

3 answers

1 accepted

0 votes
Answer accepted
Bill Sheboy
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.
November 28, 2022

Hi @Boldizsár Vermes -- Welcome to the Atlassian Community!

My understanding is that created variables are text, and contain no typing information or attribution which would allow accessing them like a JSON array.

And your second example has a similar challenge: the min() function can only operate on a number or date, and the text value has not been interpreted as either.  You might try the longer format of math expressions, to split and wrap with MIN() as that one does not indicate if it only works with numbers or dates: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Functions

Finally, from where are you getting the project version list: from a REST API call or somehow directly from an issue?

Kind regards,
Bill

Boldizsár Vermes December 5, 2022

@Bill Sheboy, thanks for your reply.

The values must be dates in my examples (there is no isDate() function to check this, but they can be formatted e.g. with .jiraDate), so min() function should work with them.

The project versions are simply accessed by the project.versions smart value.

Like y_jarma-alviz likes this
Bill Sheboy
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 5, 2022

Would you please post images of your complete automation rule and the audit log details showing the rule run for context?  Those may help to explain this symptom.  Thanks!

Boldizsár Vermes January 6, 2023

@Bill Sheboy, sorry for my late answer.

I made some further tests and have the result shown in the image below.

msedge_LXY6Pz7bQx.png

The definition of variable x is:

{{#project.versions}}
{{#not(archived)}}
{{#not(released)}}
{{#name.startsWith("Version ")}}
{{#exists(releaseDate)}}
{{releaseDate}},
{{/}}
{{/}}
{{/}}
{{/}}
{{/}}

 

The log shows me that the variable has its value as a string (size of it cannot be calculated), but after removing the last comma, and splitting it, it turned to a list (it has a size). A list of dates (date formatting works). But the earliest/latest date cannot be selected, and this is my problem.

Boldizsár Vermes January 6, 2023

The same method works well with numbers cutting from the end of release names, I can filter specified releases by their names, have the numbers from their ends and select the highest.

Bill Sheboy
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.
January 6, 2023

Hi @Boldizsár Vermes 

First thing, the only reason you can see those project versions is that the trigger is Manual, and so you are actually operating on an issue with {{issue.project.versions}}  My understanding is the stand-alone {{project}} smart value is only available with the project triggers.

Next, the closest I was able to get was to identify the earliest release date, but I was unable to select/match on the version information.  Here is what I used, by converting the date to a number so min would work.  I also combined all of the conditions using and()

varReleaseDates

{{#issue.project.versions}} {{#if(and(not(archived),and(not(released),and(name.startsWith("2021"),exists(releaseDate)))))}}{{releaseDate.format("yyyyMMdd")}},{{/}}{{/}}

 

And the smallest one would then be this:

{{varReleaseDates.substringBeforeLast(",").split(",").min}}

 

I also tried experimenting by changing the format of the values but was unable to filter the results to get the version information.

Boldizsár Vermes January 9, 2023

Hi @Bill Sheboy

I have to think that we are close to the solution but a final piece is still missing.

Your approach to get the closest date is great, works well on my side too. I tried to put it back to the initial condition list and make a comparison of that date and the release date, like:

{{#issue.project.versions}}
{{#not(archived)}}
{{#not(released)}}
{{#name.startsWith("Version ")}}
{{#exists(releaseDate)}}
{{#equals(releaseDate.format("yyyyMMdd"),varReleaseDates.substringBeforeLast(",").split(",").min)}}
{{name}},
{{/}}
{{/}}
{{/}}
{{/}}
{{/}}
{{/}}

But it doesn't work, results only the releases without a release date.
Giving an exact date/number into the equals() function results in the proper version. Why does an exact value work and a smart value doesn't?

 


 

About project.versions vs. issue.project.versions:

My guess is the first one works for me not only with manually triggered rules because they are one-project scoped rules. But following your suggestion, I will use issue.project.versions from now on.

Like Bill Sheboy likes this
Bill Sheboy
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.
January 9, 2023

Correct; when there is only one issue at a scope in a rule, things like {{issue.project}} and {{project}} are the same thing.

For the original topic, I am stumped on how to proceed. 

I also tried what you show, and tried with match(), and with home-made name/value pairs, nested iterators, etc.  Created variables do not behave consistently in functions or in smart value, list filtering.  My hypothesis, based on trying to solve similar use cases, is things just collapse to null at some point, leading to no matches: the variables appear not to parse/evaluate.  

One curious thing I noticed: when I got all of the matching/filtering syntax correct, the results were either null or all the input versions (unfiltered).  The latter makes no sense.

Boldizsár Vermes January 12, 2023

I think I found a solution which may be not nice or elegant but works. All thoughts, suggestions are welcomed to improve it or make it more robust, sustainable, etc.

First, I created a list of corresponding releases with all the data I want to use later, let's call it varReleases. I didn't combine the conditions because it is better to read and understand them this way. I use the ID of the release instead of the name to eliminate any character from the name that could ruin the functions later.

{{#issue.project.versions}}
{{#not(archived)}}
{{#not(released)}}
{{#name.startsWith("Version ")}}
{{#exists(releaseDate)}}
{{id}}-{{releaseDate.format("yyyyMMdd")}},
{{/}}
{{/}}
{{/}}
{{/}}
{{/}} 

 Second, I determined the earliest date, let's call this varDate.

{{varReleases.substringBeforeLast(",").split(",").substringAfterLast("-").min}}

Then, I created a regular expression using this date, let's call it varRegularExpression.

(\d+)-{{varDate}},

Last, I use function match() on varReleases.

{{varReleases.match(varRegularExpression)}}

This works well on my side even if no or multiple releases exist with the same earliest release date.

Like # people like this
Bill Sheboy
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.
January 12, 2023

Awesome, and well done!

I was about to try that with a homemade encoding like you show for varReleases, yet I haven't gotten a created variable to work in a regular expression match() function call before; often this was because my searches has dynamic and static content, which required quotation marks.  I'll definitely try that one in the future.

Like Boldizsár Vermes likes this
0 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 2023

Hi @ingvarr - you mention that you "sort on concatenated date and id".

How are you sorting?

ingvarr August 3, 2023

Apologies for not noticing earlier — did not properly set up notifications.

So, I create a monster of a string: 

{{#project.versions}}...{{releaseDate.format("yyyyMMdd")}}{{id}}<<<>>>...{{/}}

and then:

{{selectedVersions.substringBeforeLast("<<<>>>").split("<<<>>>").min}}

— this appears to provide the earliest.

0 votes
ingvarr July 1, 2023

Thank you very much for the helpful research. `if()` behaves badly (for me) in automations and I was struggling quite a bit.

I did a mild correction to address always finding a single release (in case there are multiple with the same date).

To do that, I sort on concatenated date and id:

...{{releaseDate.format("yyyyMMdd")}}{{id}}<<<>>>...

Then split by "<<<>>>" and sort and get the earliest created with the earliest date:

{{earliestReleaseDateAndId.substring(8)}}

 

Boldizsár Vermes July 4, 2023

@ingvarr, I am glad to hear that this solution helps others too.

I chose to add all the fix versions that meet the criteria and are the same day, but your solution works differently that can fit other purposes. Thanks for sharing it.

Suggest an answer

Log in or Sign up to answer