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

0 votes
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.

0 votes
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