How to create an Automation to copy Labels from Epics to Story/Task (Upon creation)?

Mizael Ponce June 2, 2022

Our team has adopted a new organizational method, via specified labels on all of our Issue Types. Unfortunately, I have run into a problem where I am manually applying all of the labels to the Stories/Tasks within my Epic. 

My initial goal was to proactively Label the Epic with the Team and Project Code, and have any issues created under the Epic automatically take on the labels of the Epic. 

I have been able to create an automation to make sub-tasks copy the labels of the Parent Issue, however, when I apply the same logic and use the Action: "copy from epic", the audit log informs me that it could not find the Epic to pull the information from.

Is there something I should be changing below to get this automation to work? 

 

Jira Automation.png

2 answers

1 accepted

8 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.
June 2, 2022

Hi @Mizael Ponce -- Welcome to the Atlassian Community!

Your want your rule to trigger when a child issue (e.g. story) is created...and it already points to an epic.  Is that correct?  If so, you want watch for timing problems with the Issue Created trigger and copy directly from the Epic.

  • trigger: issue created
  • action: re-fetch
  • condition: issue type is Story or Task
  • action: edit issue, setting the labels from the Epic (this is an option from the field edit via the ... at the right side of the field)

What do you want to happen if the Epic Link for an issue changes later?

Kind regards,
Bill

Mizael Ponce June 2, 2022

Hi @Bill Sheboy ,

 

Thank you for that suggestion! The automation is working smoothly now. 

Regarding your last question, I want the Issue types to take on the labels for whatever Epic they are currently linked to. 

Is there a rule I can implement for this? 

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.
June 2, 2022

For that use case, you will want a second rule triggered on issue update to copy from the epic.

Unfortunately you cannot use the Issue Field Changed trigger with "Epic Link" as that is not supported yet.  Instead you use the generic Issue Updated and add a condition, such as...

  • trigger: issue updated
  • condition: issue type is Story or Task
  • advanced compare condition: using {{changelog}} to compare for a change in Epic Link
    • first value: {{#changelog.Epic link}}{{fromString}}{{/}}
    • condition: does not equal
    • second value: {{#changelog.Epic link}}{{fromString}}{{/}}
  • and here is the tricky part... using conditions, what do you want to do if the Epic Link is cleared: clear the child's labels or leave them alone?  Add an If/Else condition here to handle what you decide to do
Like # people like this
Mizael Ponce June 3, 2022

@Bill Sheboy Thank you for this information! You just saved me a couple hours of trial and error. 

Like Bill Sheboy likes this
John Wignall January 4, 2023

@Bill Sheboy Thanks very much! That re-fetch step got me past a frustrating problem.

Like Bill Sheboy likes this
John Wignall January 5, 2023

@Bill Sheboy Well, it got me most of the way. Turns out that it works for tasks, stories, and initiatives, but not subtasks. The automation triggers, and says it edited the subtask, but the label is blank. I've got it copying from Epic, not Parent, so that part should be okay.  You've already been very generous with your expertise, but if you have a moment to sanity check me, I'd greatly appreciate it.

In the screencaps, DIS-86 is a subtask generated from DIS-85, which is a task that successfully picked up its label from the Epic using the same rule.image.pngimage.png

Like Bruno Bellini 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.
January 5, 2023

Hi @John Wignall 

When the source issue type varies like this, two solution approaches to copy data from the "parent" are to use two rules to limit scope (e.g. a rule for epic to story, and a rule for story to subtask), or to use if/else conditions in one rule.  For the second approach, that would look like this:

  • trigger: issue created
  • action: re-fetch issue
  • if/else
    • condition: issue type is story, task, or bug
    • action: edit issue to copy the labels from the epic
  • else/if
    • condition: issue type is subtask
    • action: edit issue to copy labels from the parent (i.e. story, task, or bug)
  • else/if
    • condition: issue type is epic
    • action: edit issue to copy labels from the parent (i.e. initiative)

Please adjust this accordingly as I am unclear of your type hierarchy (based on Jira license level).

Kind regards,
Bill

Like # people like this
John Wignall January 6, 2023

So a subtask can't copy labels from an epic two levels up? That's a pity. I'll give this structure a try. 
Merci Beaucoup!

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.
January 6, 2023

You can also try doing this as sometimes the structure below works, assuming the {{issue}} is a subtask}}

{{issue.parent.parent.labels}}

I recommend experimentation; this syntax does not work for everything.  If it did, a rule would need to potentially pull in every issue in a project/site!

Like John Wignall likes this
bmacd March 19, 2023

@Bill Sheboy I've been reading through this thread after having an issues with it.

I set it up successfully using a different trigger (mainly to capture any Jiras in progress - see screenshot) and what I've discovered is "Copy Labels from Epic issue" doesn't seem to be a copy but a replace/sync - ie. when triggered the labels are copied from the epic, BUT if i then add additional labels to a story when the automation is triggered again it removes those additional labels. 

Any ideas on how i can copy labels from the epic and keep additional labels in any story? 

 

copy labels from epic.png

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.
March 20, 2023

Hi @bmacd 

You are correct that the "Copy Labels from Epic issue" is a replace, not an add to existing, operation.  I recall answering this scenario before, and I'll look around to see if I can find the post/link.

The solution is to add the additional labels using advanced edit with JSON, such as:

  • branch to the epic and use list and text functions to gather the labels and build a JSON string, stored in a created variable
  • outside of the branch, use the created variable with JSON in an issue edit

As your rule is triggered on changes to Assignee and Status, this may update the issue more often than needed.  Please consider if another trigger(s) would help.

Kind regards,
Bill

bmacd March 20, 2023

Thanks @Bill Sheboy  - i found a tick box to add labels under the setting

Like Bill Sheboy likes this
Maíra Matos September 1, 2023

@Bill Sheboy  YOU ARE MY HERO

Thanks!

I've created 2 separated rules, one for tasks and other for subtasks, but i will definitely save the bigger rule using "else".

Like Bill Sheboy likes this
0 votes
Claudio Gonzalez
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.
June 2, 2022

Hi @Mizael Ponce ,

Try how I put in the attached file.

Screen Shot 2022-06-02 at 17.03.47.png

Mizael Ponce June 2, 2022

Hi @Claudio Gonzalez ,

 

Thank you for your Input! I edited the Rules to reflect your image (assuming T&A and Linux/Unix are your issue types), however I am still not seeing the label field populate on the Stories/Tasks that I am creating under the Epic. 

I am attaching an image of the Rule Details and Audit Log the for your review. 

 

Is there perhaps a field I need to include on my Epics in order for the Automation to recognize the Issue type and information I am requesting? 
Automation 1 revised.pngAutomation error 1.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events