Can I use a post function to trigger an automation rule?
Asked by Tim H_:

I need to do some rather complex operations in certain transitions, which I can't realize with the built-in post functions. However, I can use automation rules for that.

Now I'd like to know how I can trigger those rules specifically for those transitions. In Data Center, I don't see the option to use a certain transition as a trigger.

Perhaps webhooks could be a solution? At least, post functions can trigger webhooks and webhooks can trigger rules. Would that be a good idea? I don't really know much about webhooks and how to configure them.


Answers:
author: Samuel Gatica
body: Hi [@Tim H_](/t5/user/viewprofilepage/user-id/519831)

I haven't utilized webhooks in that manner before, but it should be effective.

Another option is to create a custom field and utilize the Field Value Change trigger.

Hope that helps

Best regards

Sam

comments: author: Tim H_
body: Hi [@Samuel Gatica](/t5/user/viewprofilepage/user-id/753028),

thank you for your input. I set up a webhook and it worked.

1. Create automation rule that's triggered by an incoming webhook. Copy the respective URL.

2. Add a webhook listener, use the URL and add ?issue=${issue.id}

3. Now I can use the triggering issue inside the automation rule, e.g. in order to copy values from.


author: Joseph Chung Yin
body: [@Tim H_](/t5/user/viewprofilepage/user-id/519831) -

In automation rule, you can just use the triggering event of "Issue Transitioned" to conduct your alternative post-function-like operations. Don't if you already try it or not.

Hope this helps.

Best, Joseph Chung Yin

comments: author: Tim H_
body: Hi [@Joseph Chung Yin](/t5/user/viewprofilepage/user-id/396739),

thank you for this idea. There is indeed a trigger "Issue Transitioned". However, I can't select a particular transition. I'd like to select "Workflow A, transition X". That's possible for actions, but not for triggers.

Instead, I can define a "From" and a "To" state. I can't even restrict it to a workflow. Thus, every time an arbitrary workflow that transitions from that state A to B would trigger the rule. I think that's very error-prone and can lead to unwanted effects when creating new workflows.

In my case, it wouldn't even work. I have several transitions from A to B and I want different rules to be triggered, depending on the transition.

Best regards,

Tim


author: Stefan Salzl
body: A transition is exactly this - an action from state A to state B. even though you can't choose the workflow in the trigger this could be restricted with either the type of rule (single project) and/or further with condition asking for the issue type.

Thus it will only run actions whenever the condition is met and makes the rule much easier and a lot less complex to handle and maintain.

Best  
Stefan


author: Tim H_
body: Dear [@Stefan Salzl](/t5/user/viewprofilepage/user-id/4616993),

thank you for this clarification. Unfortunately, I didn't find a way to make this work in cases where I have more than one transition from A to B and I want the rule only to be triggered for one of the transitions.

As you can see above, I found a solution by using webhooks.


author: Stefan Salzl
body: [@Tim H_](/t5/user/viewprofilepage/user-id/519831)

aaaah i see. Thanks for the clarification. Great to know you got the perfect solution for your case (y)

Best  
Stefan


author: Tim H_
body: Using webhooks to trigger automation rules works flawlessly. However, after reading [this document](https://confluence.atlassian.com/jirakb/best-practices-on-working-with-webhooks-in-jira-1180143465.html) from Atlassian, I wonder if this is a good idea. They say that using webhooks may slow down your system and that webhooks should be avoided if possible.

I was planning to use them as a trigger for automation rules. They should not listen to certain events like issue created, but are called explicitly from a post function.

I wonder...

- if it's a good idea to use webhooks like this from a performance perspective.

- if I could (should?) use custom events instead of webhooks.


author: Jamie Rogers
body: Hi Tim

A webhook post-function is just going to send a JSON payload from Jira to somewhere else thats listening for it - in our org we use these to trigger CI/CD or Ansible to then do builds or run playbooks. I suppose you could have an automation listening for this webhook on the same Jira server but I have not seen it used this way before, so unsure if it would work.

As others have suggested above there maybe be other ways to use automation to update your issues (similar to post function actions) - such as issue transition or field update triggers to start your automation.

Regards, Jamie

comments: author: Tim H_
body: Hi [@Jamie Rogers](/t5/user/viewprofilepage/user-id/1033381),

thanks for your ideas. As I mentioned in the other answer, the issue transition doesn't work as a trigger. A field update trigger could probably work. But it seems cumbersome and error prone :-(


Tags: automation

jira-service-desk-data-center

jira-service-management

jira-service-management-data-center

jira-service-management-server

server