How to remove all of the labels starting with specific word?

Branislav Toman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 27, 2024

Hi, I created automation that creates child issue under the trigger issue and inherit all of its labels. Then I need it to remove all of the labels starting with word "Create" (e.g. "CreateTask", "CreateStory",...).

I tried multiple approaches but nothing works. Closest I got was using smart value in advanced editing JSON like this, but still did not work:

{ "update": { "labels": [ { "remove": {{#issue.Labels.name.startsWith("Create")}} } ] } }

image.png

2 answers

3 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.
October 27, 2024

Hi @Branislav Toman -- Welcome to the Atlassian Community!

I believe this would need to be done in two steps: filter out the labels starting with "Create" and store the result in a variable, and add the remainder with JSON syntax when the issue is created.

  • action: create variable
    • name: varLabelsToAdd
    • smart value:
{{#issue.labels}}{{#if(not(startsWith("Create")))}}{{.}},{{/}}{{/}}

This works by iterating over the labels and removing any which start with "Create", adding a comma-separator after any values found.

 

  • action: create issue, using this JSON to set the labels:
{{#if(exists(varLabelsToAdd))}}
{
"update": {
"labels": [
{{#varLabelsToAdd.substringBeforeLast(",").split(",")}}
{ "add": "{{.}}" }{{^last}},{{/}}
{{/}}
]
}
}
{{/}}

Then use the variable, dropping the last comma, and splitting the remainder to dynamically build the JSON.  As a precaution, I added a conditional logic around that to ensure there are labels to add.

 

As an aside, you could also try using a regular expression with the match() function to remove the labels in one step.  However, and in my experience, that may not be possible as the "underlying implementation is based on Java's Pattern class" but does not support all of its features.

 

Kind regards,
Bill

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.
November 18, 2024

Hi @Branislav Toman 

I am following up to learn if this answer solved your question.  Thanks!

 

0 votes
Branislav Toman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 27, 2024

image.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events