Triggering an Automation For Jira rule from a workflow

Automation For Jira is an awesome part of the Jira toolbox. So awesome in fact that some of my clients don't purchase other apps that could make my life easier when I am implementing their business processes. One of the problems that I recently had to solve is how to trigger an Automation For Jira rule from a post-function.

In my case, the entire purpose of the transition is to execute this Automation for Jira rule, which updates a linked issue. I don't want to change the status of the trigger issue, just execute the rule when the user presses the transition button.

I came up with a couple of different ways that I could do this. One approach is to create a special custom field whose value I could change as part of the post-function. I could use the Field Value Changed trigger looking at this specific field and run it when the value of the field changed.

I rejected this for two reasons. First, as a Jira Administrator, I don't like to create custom fields that have no apparent value to the user and appears on no screens. Secondly, it creates an administrative problem because the next administrator has to rely on reviewing documentation to understand the purpose of this field. This is risky if the administrator is like me and likes to keep the Jira environment clean and tidy.

The approach that I settled on uses Automation For Jira's ability to be triggered as an incoming webhook. I created the Automation For Jira rule using the Incoming Webhook trigger. I then created an outgoing Webhook that calls this webhook passing the issue key. In the post-function, I use the Trigger a Webhook post-function to call the webhook. This triggers the rule on my issue. 

Do you have another way to trigger an A4J rule from a post-function? Do you prefer the "Field Value Changed" approach that I rejected?

11 comments

Andreas Knecht
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 25, 2021

Hi Derek,

We have an issue open to track this at https://codebarrel.atlassian.net/browse/AUT-570

Pretty sure for now the workarounds you described are the only options.

Cheers,
Andreas

Like # people like this
Maros Strmensky April 26, 2021

Hi Derek,

My first idea would be to use custom event for this. e.g. throw "Run Automat" event, and then use trigger "Multiple issue events".

It is not like doing it in the post function, but it doesn't matter, because Automation for Jira don't start rules immediately.

Best regards,

Maros 

Like Martin Cleaver likes this
Italo _Modus Create_ April 26, 2021

@Maros Strmensky ,

I had the same idea but A4J don't currently support custom events as trigger

https://jira.atlassian.com/browse/JSDCLOUD-4461

Like Martin Cleaver likes this
Benjamin Peikes September 24, 2021

Did you ever figure this out? In the past I've done something very dumb, like have the transition add a value to a field, and then in the automation rule, check for that field, run the automation, and then delete the field.

Been looking at it again lately, and I think there is another way, but I haven't implemented it. You can do it by having the trigger for the automation be an external webhook, and then have the post function run an external webhook. It's convoluted though, in that you have to also add a webhook.

Frankly, I have no idea why one of the items in Post functions for transitions is not to run an automation rule. It's completely ridiculous.

Like Martin Cleaver likes this
Martin Cleaver
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.
December 6, 2021

I assume you are creating a System Webhook in Jira's central admin panel, the issue with that is it creates an association between something centrally managed (the egress webhook) to the something defined at the project level (the a4j rule to be invoked by it). And for every rule you'd need a system webhook.

On DC, my workaround was to create a set of System Events, and queue/process events in A4J. But it creates an obvious intermediate, doesn't scale and is asynchronous so the UI doesn't update immediately.

You couldn't use a single shared webhook because you couldn't pass in a parameter.

It would be simple for Atlassian to create a "invoke rule 164" with "{json payload}"; this would permit lookup of the rule by number/name. 

I was just thinking of doing the same... cataloging the a4j rules into a lookup table indexed by rule number. It's probably easy enough in ScriptRunner. Or someone could just write an Workflow Helper app that took parameters. 

Sadly AUT-570 is now 4 years old.

Martin Cleaver
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.
December 6, 2021

As an initial implementation, a workflow helper app could just take the a4j webhook url and the payload as parameters.

While ugly/fragile/obtrusive to embed the URL it'd avoid needing to build a rule number -> url-of--rule lookup. The numbers are a bit ugly in themselves.

Also, it would be nice if the rule implementing the webhook could have an elegant way to check it received all parameters it needed and return an error code otherwise.

Martin Cleaver
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.
December 8, 2021
Martin Cleaver
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.
December 14, 2021

I was asked by a colleague why it is needed to triggering A4J from a Transition at all, as Jira Automation can listen to a loop/any->itself transition. 

Of course, the reason is to bridge the post-function and a4j technologies. There are many reasons different projects use one or the other style for automation. Some might even use both, for instance if they are modernizing towards a4j.

David Yu
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 19, 2023

Looks like this still isn't available yet today.

Seems like the least kludgy options are to either write a IssueProperty during the post-function, or like someone else suggested here, create a bunch of new Jira events, and fire those events.

C_ Derek Fields
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 19, 2023

You can trigger an Automation from a Transition by calling it through a Webhook post-function

David Yu
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 19, 2023

 

You can trigger an Automation from a Transition by calling it through a Webhook post-function

So trigger a classic "Jira Webhook" which then triggers an "Automation for Jira" rule that is listening on an incoming webhook, right? I thought about that a little, and it feels a little risky having anonymous webhook endpoints exposed.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events