Filter labels and save to string in automation

Christof Hurst
Contributor
November 22, 2024

Hi, 

after a migration I have multiple Labels (all with prefixes). With these I want to make JQL and Reassign Assets. 

So e.g. these labels: 

firm-EDI-310474, firm-EDI-4747743, firm-EDI-660640, mess-EDI-282211, mess-EDI-282219, prot-AS2

I need a string from all labels with prefix "firm-" like 

EDI-310474, EDI-4747743, EDI-660640

I tried everything with parsing through labels, conditions in any syntax possible But I didn't come to an end.

so some kind of

{{issue.labels.match("firm-.*").join(", ")}}

Any ideas?

 

2 answers

2 accepted

1 vote
Answer accepted
Mykenna Cepek
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.
November 29, 2024

Despite posts elsewhere lamenting that you can't iterate over the Labels field effectively, I think I can get you very close.

I started with an issue that had a bunch of labels:

1.PNG

Your prefix is "firm-" and my prefix is "M". Note that your prefix is 5 chrs long, mine is 1 chr long.

This smart value:

{{#issue.labels}}{{#if(startsWith("M"))}}{{substring(1)}}, {{/}}{{/}}

produces this text output:

2.PNG

For your situation you'll want to change the substring(1) call to substring(5) to skip all of your prefix, and of course change "M" to "firm-".

We can't use the {{^last}} trick in automation list iteration here (to omit the final comma) because the list of labels might very well contain labels after the last matching one. So don't bother.

If you really need to remove the trailing comma (and space), you can store this string in a variable and use the substring() and length() functions to remove the last two chrs.

0 votes
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 29, 2024

Hi  @Christof Hurst 

As I don´t get the whole use case (where and how this flow should start, where to find the pattern,....) I just started how this could even be iterated with a "log action".

the follwing at least gave a filtered list of labels starting with "firm". Maybe this could be at list a starting point or hint how to go on:

{{#issue.labels}}{{#if(startsWith("firm"))}} {{.}} {{/}}{{/}}

 

Looking forward hearing from you.

Best
Stefan

Suggest an answer

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

Atlassian Community Events