The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do an exact match on label field using "If" statement in automation?

Tom Scoggin
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 Champions.
July 30, 2024

I have tried everything to get an exact match on an If statement in an automation, but it keeps coming up with putting the issue in both categories. The issue has the label of "DEV-APPROVAL" but it keeps getting added to the "DEV" section. Here are the if statements.

 

{{#if (labels.match("(DEV-APPROVAL)").size.gt(0))}}

{{#if (labels.match("(DEV)").size.gt(0))}}

 

Sample of code

{{#issues}}

{{#if (labels.match("(DEV-APPROVAL)").size.gt(0))}}

<ul style="font-size:18px;">

<li><strong><a href="{{url}}">{{key}} - {{summary}}</a></strong>

<ul><strong><li>Description:</strong>{{description.html.remove("<p>").remove("</p>")}}</li>

***and more***

{{#issues}}

{{#if (labels.match("(DEV)").size.gt(0))}}

***same as above..***

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
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 Champions.
July 30, 2024

Hi @Tom Scoggin 

Because the DEV value is a substring of DEV-APPROVAL, the expression for match() will need to exact match, perhaps using the start and end tokens:

{{#if(labels.match("^(DEV)$").size.gt(0))}}

 

Kind regards,
Bill

Tom Scoggin
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 Champions.
July 30, 2024

Thanks Bill. That worked perfect. Do you know where I can find that in the documentation?

Like Bill Sheboy likes this
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 Champions.
July 30, 2024

Awesome; I am glad to learn that helped!

 

Regarding documentation, in the automation documentation on the match() function, it links to some regular expression information from the Java spec that rules are based upon: https://confluence.atlassian.com/automation/jira-smart-values-text-fields-993924863.html#Jirasmartvaluestextfields-matchmatch()

Please note it states "is based upon" that spec, but no where does it state what exactly is (or is not) supported.  In my experience, I always test and experiment to learn what works with rules.