When creating workflows in Automation for Jira, repeating actions a specified number of times can be a desirable function to have.
While Automation for Jira has powerful Branching Components, they are reliant upon a list of issues, or other entities to act upon. This can be cumbersome to use in place of a number.
Sometimes, a simple "run through this workflow 3 times" is all that's needed. This article will cover creating a pair of Automation Rules that provide this functionality.
The structure of this configuration relies upon a few Automation Rule Components:
It is advised that the looping rule be disabled while it is being configured. If the rule is looping continuously, disable it to halt the feedback loop.
The first rule will be structured like so:
Trigger: <the initial action that should begin this process> - This depends on what these rules are achieving and your business needs regarding it.
Action: Send Web Request →
Web request URL: <Webhook URL>
- Example: https://automation.atlassian.com/pro/hooks/<unique-id>
- This is attained from an Incoming Webhook Trigger on the 2nd Rule.
Headers:
- Content-Type: application/json - Do not check Hidden
Method: POST
Web request body: Custom Data
Wait for response: Do not check either of these.
- Delay execution of subsequent rule actions until we've received a response for this web request
- Continue running the rule even if the request response is not successful (i.e. non-200 response)
The Custom Data should be a JSON Payload that contains the value that will be used to determine how many cycles will occur.
A simple example would be:
{"value": 3} |
However, this value can be dynamic. If it comes from a Smart Value, it typically will be.
That is the entirety of the first rule. The second rule is only slightly more complex:
Trigger: Incoming Webhook
- The URL this provides is used in the Send Web Request for the 1st rule. Set Execute this automation rule with to whatever is needed for your use case. The value that will be used is required.
Condition: Advanced Compare → The Value from the JSON Payload is Greater Than 0.
Action: Send Web Request →
Web request URL: <Webhook URL>
- This is attained from this rule's own Incoming Webhook Trigger. i.e. itself.
Headers:
- Content-Type: application/json - Do not check Hidden
Method: POST
Web request body: Custom Data
Wait for response:
- Check this → Delay execution of subsequent rule actions until we've received a response for this web request
- Do not check this → Continue running the rule even if the request response is not successful (i.e. non-200 response)
The Custom Data should be the same as before, except that it needs to decrement the value first. It is advised that dynamic values are only provided by the 1st rule. This way, since a decrement on a static value occurs in the 2nd rule, the number can only go down. This prevents the 2nd rule from running continuously.
Using the simple example before, it would be like this:
{"value": {{webhookData.value.minus(1)}} } |
And that's the entirety of how to accomplish this task. It is important to note that misconfiguration can lead to Automation Rule Throttling, per our Automation Service Limits. Caution should be used when creating these rules for this reason.
If this rule were to receive an Incoming Webhook without the appropriate value, it simply wouldn't run, thanks to the Condition.
Payden Pringle
0 comments