Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Automation for Jira: How to match a string to insert into different field?

Jenni Järvinen May 1, 2020

My company uses Jira Cloud with GitLab integration. Every time merge request in GitLab has the Jira issue key added into it, the GitLab integration adds a "mentioned on" issue link, as shown below:

gitlab-link.PNG

This link points to an URL which is format of: https://<my-company-url>/merge_requests/1359

Our issues also have custom field for the merge request data (used in Confluence for Jira issue filters), shown as below:

morko.PNG

Currently the custom field is manually filled with copy&paste after the "mentioned on" link has appeared, but I'm looking for a way to automate this.

Basically what I need to do is to parse the last four digits of the URL where the "mentioned on" link points and insert them into the custom field (shown above) as in the picture shown above.

Is this possible?

3 answers

1 accepted

0 votes
Answer accepted
Bloompeak Support
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 1, 2020

Hi @Jenni Järvinen ,

I hope below "Issue commented" trigger works.

When: Issue commented
If: Compare two values
First Value={{comment.body}}
condition = contains
second value = |https://my-company-url/merge_requests/

Then Edit issue fields
Choose fields to set = your custom field
Value = {{comment.body.replaceAll(".*(https://my-company-url/merge_requests/[0-9]+)\].*","$1")}}

 

Screen Shot 2020-05-02 at 05.14.37.png

0 votes
Jenni Järvinen May 1, 2020

Hi @Bill Sheboy ,

and thanks for your answer. Still not sure how to proceed that, mostly because not sure how/where to trigger the parsing action. 

The URL with the digits I need to parse is visible on the JSON data (below), but no idea how to get it from there?

This is the JSON data of one ticket which has the GitLab mention, and it looks like this (URLs and usernames edited for privacy):

"comment": {"comments": [{"self": "https://my-company-url/rest/api/2/issue/102106/comment/190277","id": "190277","author": {"self": "https://my-company-url/rest/api/2/user?accountId=557058%3Ae1b49e38-24c3-4915-bcd3-dd4635b37a50","accountId": "557058:e1b49e38-24c3-4915-bcd3-dd4635b37a50","avatarUrls": {"48x48": "https://secure.gravatar.com/avatar/356a95e0d2e26887ad96b01aa621105b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FGI-2.png&size=48&s=48","24x24": "https://secure.gravatar.com/avatar/356a95e0d2e26887ad96b01aa621105b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FGI-2.png&size=24&s=24","16x16": "https://secure.gravatar.com/avatar/356a95e0d2e26887ad96b01aa621105b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FGI-2.png&size=16&s=16","32x32": "https://secure.gravatar.com/avatar/356a95e0d2e26887ad96b01aa621105b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FGI-2.png&size=32&s=32"},"displayName": "Gitlab Integration","active": true,"timeZone": "Europe/Helsinki","accountType": "atlassian"},"body": "[Author|https://my-company-url/author] mentioned this issue in [a merge request of repo/project|https://my-company-url/merge_requests/495]:\n'CMW-141: Add hayu code to user after registration'",

The problem is that I'm not sure how to handle that data. I've played around with Jira automation quite a lot but never anything this complicated.

a) In which step of the automation is the data parsed, and how?
b) How is the parsed data then included in the custom field?

Those two things are the ones I'm struggling with. I've been reading pages and pages of docs but I could really use a clear example that I can then edit and modify on my own.

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.
May 1, 2020

Hi @Jenni Järvinen 

Perhaps I misunderstood.  I thought that you were already integrated to the point where you were updating a Jira issue with a comment for the mention.

Is your Jira issue getting such a comment with merge information?  If so, please try a comment trigger, and then parse out the merge request data:

https://support.atlassian.com/jira-software-cloud/docs/automation-triggers/

 

Also please note that nesting of smart value functions does not appear to be possible.  So if that entire JSON is landing in the Jira issue comment, you may need to parse it in steps using multiple custom fields and rules.

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.
May 1, 2020

Hi @Jenni Järvinen 

Have you tried automation rules, triggered on the mention, and then parse out the number using the function substringAfterLast, looking for the "/"?

Here is the complete help on that function: https://support.atlassian.com/jira-software-cloud/docs/smart-values-text-fields/

And here is the how-to for getting started with the automation:

https://www.atlassian.com/software/jira/guides/expand-jira/automation

 

Best regards,

Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events