Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Regex to populate Fix Version Field?

Heather Ronnebeck
Community Champion
April 21, 2025

Hello!

I've got another automation question for everyone. I am trying to do the following:

  • If a custom field (called Platform for this purpose) has iOS as a selected option, then add the unreleased iOS-1.2.3 version to the fix version field. 
  • If the same custom field has tvOS as a selected option, then add the unreleased tvOS-2.3.4 version to the fix version field. 

Note: The versions will always change, the only thing consistent is that they will all start with either iOS or tvOS and there will only ever be one unreleased version of each kind at any given time.

My idea on this so far has been to attempt this with regex, but I don't think Jira Automation can accept Regex in their lookups. Does anyone have any ideas on this one?

Thanks in Advance!

3 answers

2 accepted

1 vote
Answer accepted
Darryl Lee
Community Champion
April 22, 2025

Oh hi @Heather Ronnebeck - yes what @Bill Sheboy said.

Here's the details from a rule I created and tested:

Send Web Request:

https://YOURSITE.atlassian.net/rest/api/3/project/{{issue.project.key}}/versions

Headers:

Content-Type: application/json

Authorization: Basic youremail:token base64encoded

Create variable - {{unreleasedVersions}}

{{#webResponse.body}}{{#if(equals(released, false))}}{{name}}{{^last}},{{/}}{{/}}{{/}}

If: matches - Platform equals iOS

Create variable - {{iOS}}

{{unreleasedVersions.match("(iOS-[^,]*)")}}

Edit issue fields - Advanced

Additional fields:

{
"fields": {
"fixVersions": [{"name" : "{{iOS}}"}]
}
}
}

Else-if: matches - Platform equals tvOS

Create variable - {{tvOS}}

{{unreleasedVersions.match("(tvOS-[^,]*)")}}

Edit issue fields - Advanced

Additional fields:

{
"fields": {
"fixVersions": [{"name" : "{{tvOS}}"}]
}
}
}

So I did end up using Regex, but only because my filter based on platform didn't work:

{{#unreleasedVersions.split(",")}}{{#if(name(match("iOS-.*").size.gt(0)))}}{{.}}{{/}}{{/}}

I was getting this gnarly error:

Error invoking method com.codebarrel.automation.api.component.smartvalues.objectwrappers.CollectionWrapper.Element.get(java.lang.String@320875173) on com.codebarrel.automation.api.component.smartvalues.objectwrappers.CollectionWrapper.Element@823855090: {{#unreleasedVersions.split(",")}}{{#if(name(match("iOS-.*").size.gt(0)))}}{{.}}{{/}}{{/}}

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.
April 22, 2025

Hi @Darryl Lee 

Both the name filtering (by query) and the status filtering may be sent in the original endpoint call using parameters.  Further list filtering may only be needed for more advanced name (or other data attribute) filters.

Thanks, and kind regards,
Bill

Darryl Lee
Community Champion
April 22, 2025

Ohey @Bill Sheboy  I looked at the docs for the project versions API endpoint last night and the only query parameters I saw were expand.

OH... but I did not look at the old (v2) endpoints. Get project versions paginated has both query and status parameters you can query. Nifty.

So I guess this could be rewritten (no regex needed) as:

If: matches - Platform equals iOS

Send Web Request:

https://YOURSITE.atlassian.net/rest/api/2/project/{{issue.project.key}}/version?status=unreleased&query=ios

Headers:
Content-Type: application/json

Authorization: Basic youremail:token base64encoded

Edit issue fields - Advanced

Additional fields:

{
"fields": {
"fixVersions": [{"name" : "{{webResponse.body.values.first.name}}"}]
}
}

Else-if: matches - Platform equals tvOS

Send Web Request:

https://YOURSITE.atlassian.net/rest/api/2/project/{{issue.project.key}}/version?status=unreleased&query=tvos

Headers:
Content-Type: application/json

Authorization: Basic youremail:token base64encoded

Edit issue fields - Advanced

Additional fields:

{
"fields": {
"fixVersions": [{"name" : "{{webResponse.body.values.first.name}}"}]
}
}
}

Two ways to skin a cat. That poor cat. :-D

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.
April 22, 2025
Darryl Lee
Community Champion
April 22, 2025

How embarrassing, you're completely right, I just didn't scroll up haha.

I guess I should point out that the endpoint is different by an s:

No query parameters:

https://YOURSITE.atlassian.net/rest/api/3/project/{{issue.project.key}}/versions

Query and status parameters:

https://YOURSITE.atlassian.net/rest/api/3/project/{{issue.project.key}}/version

Tricky.

Heather Ronnebeck
Community Champion
April 24, 2025

@Darryl Lee and @Bill Sheboy 

Thank you so much for the help. It has gotten me 95% of the way there, now there's one last kink in my automation which is the scenario of when there are both tvOS and iOS in the field and both versions need to be mapped into the field. 

I have tried using 

https://<Yoursite>.atlassian.net/rest/api/2/project/{{issue.project.key}}/version?status=unreleased

this to get the versions, which it does. 

But then the issue I run into is that I can't get them into the fix versions field. That's where my hiccup is. 

I create the variable of {{apple}} with {{webResponse.body.values.name}} and then use {{apple}} to edit the Fix Version field. However, since it does work it doesn't error out on the audit log, but it also doesn't populate the field. Any ideas? 

Darryl Lee
Community Champion
April 24, 2025

OH that's tricky. So MAYBE, just maybe instead of doing:

  • IF iOS 
  • ELSE tvOS

You instead do:

  • IF iOS 
    • WebRequest to get iOS version
    • ADD version to fixVersions (instead of current REPLACE)
  • ELSE
    • audit log saying not iOS
  • IF tvOS
    • WebRequest to get tvOS version
    • ADD version to fixVersions (instead of current REPLACE)
  • ELSE
    • audit log saying not tvOS

Let me give that a spin.

 

 

Darryl Lee
Community Champion
April 24, 2025

Ah yeah, it works. Here's the iOS IF branch after I created a new IF branch for tvOS and dragged all the actions down to it.

image.png

New JSON for adding fixVersions:

{
"update": {
"fixVersions": [{
"add" : {
"name" : "{{iOS}}"
}
}]
}
}
Heather Ronnebeck
Community Champion
April 24, 2025

More like:

  • IF iOS 
    • WebRequest to get iOS version
    • ADD version to fixVersions (instead of current REPLACE)
  • IF tvOS
    • WebRequest to get tvOS version
    • ADD version to fixVersions (instead of current REPLACE)
  • ELSE
    • WebRequest to get iOS version
    • ADD version to fixVersions (instead of current REPLACE)
    • WebRequest to get tvOS version
    • ADD version to fixVersions (instead of current REPLACE)

Would that work?

Heather Ronnebeck
Community Champion
April 24, 2025

I got it!!! It works!! 

So what I needed to do was add a few re-fetchs in there and then also make sure I checked off the checkbox for:

Delay execution of subsequent rule actions until we've received a response for this web request

The part that I was stumbling on before you last update @Darryl Lee was the add vs replace. 

@Bill Sheboy @Darryl Lee thank you so much for this help. I appreciate it.

Like Bill Sheboy likes this
Darryl Lee
Community Champion
April 24, 2025

I think if you do two IF-ELSES then both will complete, and you'll get what you want.

I don't think I can advise removing the Delay. You absolutely need to WAIT for the response back from the API before trying to set the version.

I'm surprised if what you wrote worked, @Heather Ronnebeck because historically, if an IF clause failed, the rule would stop. So if the issue only had tvOS, it might not get set. That's why I added the ELSE.

@Bill Sheboy is that your recollection to how IFs used to work?

If Automation has changed how it deals with failed IFs, then... what you could get rid of is your last ELSE statement.

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.
April 25, 2025

With the if / else condition, the sections are apparently mutually exclusive: only one (or none) will execute, and...an if / else condition will not halt rule execution.  This is based on my testing / observation.

1 vote
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.
April 22, 2025

Hi @Heather Ronnebeck 

Short answer: the rule will need to use the REST API endpoint (with the Send Web Request action) to find the version to add, filtering by the name prefix and the status, and then add it using JSON.

Kind regards,
Bill

0 votes
Pablo Vergara
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 22, 2025

Hi @Heather Ronnebeck 

Have you tried something like the example below? I'm using a multi-select list field for testing (customfield_10157 in the images). It also uses regex; you can add another IF condition for the iOS matches.

I hope it's helpful as guidance for you!

- Pablo

1.png2.png3.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events