Hello,
I'm trying to dynamically apply tags based on the issues summary when an issue gets created. In short we have an automation that creates stories with a predicable naming convention for the summary example: FirstWord SecondWord ThridWord ForthWord. These words all mean something to the team but there are too many variations to build out every case and match.
I would like to have the SecondWord and the ThridWord be added as labels dynamically but I'm having trouble getting the automation to work correctly. I've been using the Smart Value (REGEX, Group#) but its only returning empty every time. Here is the actual code I've used:
{{issue.summary.match(\"^\\[([^]]+)\\]\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+).*\",1)}}
I've tried simplifying it to even {{issue.summary.match("(\\S+)",1)}} in my testing but it always returns nothing while running "successfully" in the audit. I confirmed its retuning nothing through adding a comment for all the outputs. I have also tried it with \\\\ instead of the \\ with the exact same result. Is what I'm trying to do even possible?
Hi @Shaun Hall -- Welcome to the Atlassian Community!
Short answer: I recommend using split() and get() text functions to extract the values for your label creation, and then adding them using a JSON expression.
For more information...
In the documentation for the match() function, it describes this (with italics added by me):
match()
Performs a regular expression search and returns the first (and only one) matching regular expression group.
The underlying implementation is based on Java's Pattern class and uses Matcher.find() to find matches. If multiple matches are found, they return as a collection that can be iterated...
There is no documentation on what is (or is not) supported for the regular expression implementation in rules. You may find several community posts where people tried an expression that worked in other tools / testers which did not work in rules. In my experience, I have found problems with escaping characters, order of operations, and order of parsing when smart values are used in dynamic, regular expressions.
My suggestion is to start with the simplest regular expression that can possibly work, test, and incrementally improve it to cover what is needed (and perhaps edge cases).
To save time, experimentation, etc. you could instead split your Summary field and grab the needed items from the resulting list of values. Assuming your text has space delimiters, that would be this for the Second and Third words (using a 0-based index):
{{issue.summary.split(" ").get(1)}}
{{issue.summary.split(" ").get(2)}}
Those could be added one at a time with different rule actions, or with a single issue edit with JSON:
{
"update": {
"labels": [
{
"add": "{{issue.summary.split(" ").get(1)}}"
},
{
"add": "{{issue.summary.split(" ").get(2)}}"
}
]
}
}
You may want to include a Smart Values Condition before the edit to confirm enough entries are returned by the split(), such as with this:
Kind regards,
Bill
Thank you for this suggestion! That worked exactly like I wanted to and its way simpler than how I was trying to do it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.