Matching only 1 occurrence with Regex with Automation plugin

David Yu
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.
September 21, 2018

I'm using the JQL Match feature to regex against an incoming webhook text for matching issue keys.

By default, the .match() function will return either a single issue key, or a set of issue keys. There isn't an option to always return only the first match.

Using .match().first returns the first result, but only works if a collection was found, doesn't work if only one key exists. Calling .first on a single issue just returns a blank result.

I end up with this workaround which looks a bit messy, but will limit the result to only one issue key:

{{webhookData.pull_request.title.concat(" DUMMY-3535").match("\b([A-Z]+-\d+)\b").first)}}

If there's a better way, please let me know. Thanks!

1 answer

1 accepted

0 votes
Answer accepted
andreas
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.
September 23, 2018

Hi David,

Yeah sorry - your workaround is the only way to achieve this currently.  For convenience reasons, if there's only a single match, then we just return that match (not an array), which works great in 90% of the use-cases of this method where users just want to match a single bit of text.

In this case that approach breaks down though, so you need to go with the work-around that you've put in place.

Cheers,
Andreas

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events