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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,464,669
Community Members
 
Community Events
176
Community Groups

How to return a specific label that contains a substring from multiple labels?

Edited

I am writing some automation for JIRA and I want to be able to return a specific label that contains a specific substring from a list of multiple labels.

For Example: There are two labels: abc123, 123456. I want to return the label with an "abc" substring. I have tried the following with no success:

 

{{issue.labels.first.contains("abc")}} -> returns true or false but i want the actual label, not a boolean.

{{issue.labels.match(*.abc.*)}} -> does not return anything.

 

I thought that i could just find the first element in the label list that contains a substring but it doesnt seem to be that easy. Any help would be great thanks!

1 answer

1 accepted

1 vote
Answer accepted
Mark Segall Community Leader Mar 28, 2022

Hi @Axel Kerksiek and welcome to the community!

Can you please provide a bit more context around what you are trying to do?  Are you simply trying to evaluate issues where they contain labels that begin with "abc"?  If so, what is your intended action that you plan to take with that information?  This would help in providing a quality answer.

Hey @Mark Segall thanks for the reply. So I am making some Automation in JIRA to send a slack message every time a certain issue type that has a label containing a specific string gets created. I already figured out all the filtering logic and slack integration logic, and I am on the step where I send out a message to slack. In the message body I want to be able to get the text value of the label that has a specific string.

I.E. If there is a label that has the string "abc123" I want to be able to access that label and place it in the message body, such as "the label abc123 exists".

The problem I seem to be having is that I cant return the label element based on the condition I am specifying. So when I try something like {{issue.labels.first.contains("abc")}} I get either true of false as the output value, but what I want is the label itself that passed the condition. 

Hope that helps provide more context, and thanks for the help!

Mark Segall Community Leader Mar 28, 2022

ok... So the thing about labels is that they are lists.  You could try playing around with some variation of {{#issues.labels}}...{{/}} or...

You could capture labels as a variable and branch off of that which is the route I took:

2022-03-28_16-47-47.png

Here's further context:

varLabelRaw

{{issue.labels}}

varLabel

{{varLabelIterate.match("(abc\d+)")}}

 Again, there may be a way to do this without branching into the labels, but this is what worked for me.

Thanks for the info! I think my situation is slightly different so I tried to take your advice and match it to what I'm trying to do. Based on your feedback I tried the following but was still unable to get it to work:
SampleAutomationRules.png

I created a foreach loop (set the smart value to {{issue.labels}} and gave it a variable name of varLabel).

Then I created an if statement that checked if varLabel contains a string.

Then if that succeeded I created a variable called targetLabel (Variable name is targetLabel and smart value is {{varLabel}}). 

Then i tried to access {{targetLabel}} in my message body. However when I run this I dont get anything.

Do you know what I might be missing?

If it was code I would write the logic like this (assuming there is only one label containing the target substring):

var targetLabel;

foreach(label in labels)

{

   if(label.contains("regression"))

    {

       targetLabel = label;

    }

}

print(targetLabel);
Mark Segall Community Leader Mar 29, 2022

I believe there is a limitation in Jira that variables created in a branch only exist within the branch, so you may need to move your slack action into the branch for it to read targetLabel.  If you still see nothing, I would add an audit log action right after your variable just to make sure it is in fact capturing something for targetLabel.

ah ok that worked, thanks for your feedback and help! 

Like Mark Segall likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events