Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

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 Leaders.
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

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 Leaders.
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 Leaders.
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 Leaders.
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.

Suggest an answer

Log in or Sign up to answer