Hi, I'm looking help to set up a JIRA Automation rule that will label all tickets in a sprint (on sprint start) with a substring of characters from within the sprint name.
The desired label is to be "PI XX.X" where X represents a number and this could occur anywhere in the sprint name.
I have created an automation rule that will work (on sprint start) if this desired substring appears as the first 7 characters in the sprint name, but I want to make this more versatile to be able to find this substring wherever it occurs in the sprint name.
{
"update": {
"labels": [{
"add": "{{sprint.name.substring(0, 7).replace(" ", "_")}}"
}
]
}
}
I have been looking into resolving this with REGEX pattern matching, and have a REGEX pattern that will find the required substring, but I've not yet been able to use this Match to create the desired label:
{
"update": {
"labels": [{
"add": "{{sprint.name.match(PI\s\d{2}\.\d)}}"
}
]
}
}
As the sprint field is a list, I wonder if using match() is potentially also producing a list of results. Try writing that smart value with the regular expression to the audit log to see if that is the case. If so, perhaps then referencing just one item from the list would meet your need.
Kind regards,
Bill
Hi Bill, thanks for your reply. I've not made progress with the MATCH approach, so I was wondering if there is a way to use Substring with Indexof and a set length? For example, find the Index of the string "PI ", and use this index as the starting parameter in the Substring function? The second challenge with this is the End INT needs to be this Index Value + 7.
I've come back to this as labelling from the substring extract worked, but was limited by the desired text needing to be at the start of the sprint name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My testing in other rules indicated that smart values could not consistently be used as parameters to functions like substring. There is something about the order of evaluation that seems to lead to nulls in the middle, breaking the calls.
I recommend giving match() another try, perhaps by first listing examples of what the sprint name could contain, and then practice writing the expressions to the audit log. Once you have something that works, try to add the labels with it. The tricky part of this is the regular expression, as the help indicates:
The underlying implementation is based on Java's Pattern class and uses Matcher.find() to find matches.
And I recall seeing several things defined for the Java implementation of regular expressions which are not supported by automation rules in match(). Try simpler expressions, when possible.
Also, I do not believe you need to use JSON to add a label with smart values; instead you can type in the expression with Edit Issue, Labels, add label...the smart value will appear below the field when you type it, and then you may select it for use.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy , thanks for your input. I've managed to create a working rule using MATCH():
{
"update": {
"labels": [{
"add": "{{sprint.name.match(".*(PI.....).*").replace(" ", "_")}}"
}
]}
}
This Identifier + Wildcards lifts the desired text string and uses that to create the label:
Action details:
Edit Issue:
Issues edited successfully
LOG ACTION
Log
Match value is: "PI_22.4"
LOG ACTION
Log
Sprint name is: "team 2 - PI 22.4 - Sprint 3"
Tightening up the pattern matching to look specifically for PI XX.X would be great to remove the risk of "PI" occurring earlier in the sprint name before the desired label, and any guidance you might have on that aspect would certainly be appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One concern is how are the sprint names created. If there is another automation rule/script creating them, you could rely on a stable format. But if they are manually created it is certainly possible you could have multiple or no matches.
If your names are automatically generated and always match the pattern, your expression is probably fine. However once you get past (what I assume to be) two-digits in your Program Increment number, this will break. So you could instead assume \d doesn't work in the rule implementation of regular expressions, and try something like this:
match(".* (PI [0-9]+\.[0-9]) .*").replace(" ","_")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unforuntately sprint naming is a manual action so is still open to associated formatting risks. When naming a sprint, the requirement will be to use the tag "PI XX.X" somewhere in the sprint name, however the benefit of this match() approach is this can now appear anywhere in the sprint name, and not be constrained to the start of the name as was the requirement for the substring rule.
Testing your suggested pattern match against the initial rule, I've noticed both address the concern I had, namely that the presence of "PI" earlier in the sprint name would be sufficient to trigger the Match, and therefore create an incorrect Label, but both work correctly
Edit issue
Issues edited successfully
DP-133
Log action
Log
Match value is: "PI_22.5"
Log action
Log
Sprint name is: "PI team - PI 22.5 - Sprint3"
I need to understand the wildcard criteria better, but this seems to meet the need so far. Thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I keeping thinking about creating a test rule (or rules) to exercise the regular expression functions to pin this down: what works and does not. Gotta find some free time 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.
Yes, I was surprised by the result of this 'negative' test. For the for the sake of time, i'm accepting this works though as you say, I would like to better understand the operation of this regular expression. Thanks for your help with this.
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.