Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,464,906
Community Members
 
Community Events
176
Community Groups

Jira Automation - Get the next unreleased version by criteria

Edited

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}}

1 answer

1 accepted

0 votes
Answer accepted

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

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

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!

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

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.

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.

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

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.

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 Bill Sheboy likes this

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

Suggest an answer

Log in or Sign up to answer