Hello, really stumped.
I am on Data Center version 10.3.12
Long story short, I have need to extract a partial string from a set of text from a webhook. I am trying to use native automation vs. Scriptrunner due to some organizational limitations.
I have tried various regex options but apparently DC does not support a lot of them like match and extract. Also, I know JIRA stores variables as strings and you have to convert them to numbers.
So what I was able to do is get the index of the start of the string I want to extract, stored that as a variable, then figured I can use the index value plus notation to get the next 5 characters that I want. But I am still having issues.
I am debugging by writing to the log, but while the automation does not fail or error, nothing is getting writing to the log. It seems the asNumber may not be working either.
It is probably a brain cramp on my end with a simple fix, but I am not able to see it.
Hi @daniel.jones ,
Could you post an example of the data and an example of what you want to extract?
the string will look like this
[Feature][MATRIX][Code 2025.4.5][ABC-62088] Migration Service – CI/CD Setup for EU
I need to get the JIRA key, ABC-62088. or at least the 5 digit number from that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
also, if it helps, the variable dashIndex is this
{{webhookData.pullRequest.title.indexOf("ABC-")}}
and issueTitle is this
{{webhookData.pullRequest.title}}
they both work and produce what is expected
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, suppose you have the string you mentioned in a var called 'string'
string: [Feature][MATRIX][Code 2025.4.5][ABC-62088] Migration Service – CI/CD Setup for EU
Then you create a new var called myKey:
myKey: {{string.match("\[((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)\]")}}
This will output ABC-62088, as you can see below. The regex will search for a Jira key within square brackets, so if another key is located in text at the end, you still get the correct key.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Rudy Holtkamp thanks for the suggestion. I dont know if it is because I have Datacenter version or what, but match and extract dont work. They always return empty and dont write to the log.
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.
Thank you @Rudy Holtkamp I had tried before, but maybe I goofed something up. I was able to get the info I wanted through a rather inelegant workaround. So I have the key of the sub-task I want, but am having serious brain cramps now as I can not figure out how to get the action I want (transition, but just trying comment for debugging now) on that sub-task. Since the trigger is a webhook there is no "trigger issue". I tried to branch on JQL using the key I was able to extract (I also tried it with the key hard-coded to test) but the add comment action does nothing.
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.
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.
Strange, It did when I tried it on a Jira DC instance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Rudy Holtkamp I wanted to let you know that your post above where you recommended this
myKey: {{string.match("\[((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)\]")}}
worked.
The reason it did not before was due to the way I had the webhook trigger set up.
So thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Update-I gave up on match or extract, it seems they dont work in my Datacenter version? Glad if someone can prove me wrong.
But substring does work, so I updated my script.
I create a variable called keyStart with {{webhookData.pullRequest.title.indexOf("ABC-")}} and it produces the result desired.
Then I created a variable called keyEnd with {{#=}}{{webhookData.pullRequest.title.indexOf("ABC-")}} +9 {{/}}
This works as the key is always 9 digits-ABD then a dash, then 5 numbers
But when I try substring I am running into issues. If I hard code with numbers it works, but there is not a defined start and end every time, it will vary. So I wanted to use the variables for the start and end of the substring.
Works {{webhookData.pullRequest.title.substring(5,14)}}
None of the below work
{{webhookData.pullRequest.title.substring(keyStart,keyEnd)}}
{{issueTitle.substring(keyStart.asNumber,keyEnd.asNumber)}}
{{webhookData.pullRequest.title.substring({{keyStart}},{{keyEnd}})}}
{{issueTitle.substring({{keyStart.asNumber}},{{keyEnd.asNumber}})}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
These are never going to work:
{{webhookData.pullRequest.title.substring({{keyStart}},{{keyEnd}})}}
{{issueTitle.substring({{keyStart.asNumber}},{{keyEnd.asNumber}})}}
Within {{ }} you should not use {{ }} again. So the bold ones are not going to work.
But I guess you already knew that.
--
I don't know why, but sometimes it helps to create a var and then use the functions. So create a var called title with {{webhookData.pullRequest.title}}, then use
{{title.substring(keyStart.asNumber,keyEnd.asNumber)}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@daniel.jones
I was running into problems using regex functions in automation as well. Also in 10.3
I was able to get it to work by using a specific regex and variable formatting. Details here. Hope this is helpful for the future.
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.