I'm trying to create an automation as such:
When a Test issue type is created, look at the linked Story issue type and determine the Epic associated with that Story. Once it gets that Epic, add a label to the Test indicating the Epic ID.
What I don't know how to do is look up that Epic ID associated with the Story that's associated with the Test. Any ideas?
Assuming your "Test" issue type is at the Subtask level (not the Story level) in the Jira issue hierarchy, then the following might help you.
I created a test rule that can be manually invoked on any Subtask-level issue.
It will look up the parent Story, and then the parent Epic for that Story. The results are written to the log for that rule in Automation. Here's the output I got from my testing:
Rule triggered on Sub-task AAP-309 -- Parent Story is AAP-260 -- Epic is AAP-8
I like using manually triggered rules to help figure things out. Tip: configure them for just one project (ideally a "playground" project) -- the default is that new rules are global to all projects.
Again, I'm assuming your "Test" issue type is a child of a Story (not a peer, and not a literally Linked issue). The wording in your original post is a bit ambiguous, particularly since "linked issues" in Jira have a meaning that is independent of the issue hierarchy.
Also, just know that Jira Automation does NOT treat an Epic as the "parent" of a Story:
This important detail is not real obvious from the documentation:
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events