Automation - "every other week" schedule?

Michael Woffenden
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 18, 2023

We have dozens of Jira Server automation rules, and use automation regularly to create issues on a regular schedule.  Since automation uses cron to schedule, we've been able to handle every case. 

Until now.

Our need is to create a new issue every other Wednesday.  Note that this is NOT the first and third week of the month.  Our need is actually every other week.

It seems that cron can't handle this, so is there some other creating way we can get this done inside of Jira automation?

1 answer

0 votes
Oday Rafeh
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 18, 2023

Hi , 

You're correct @Michael Woffenden that cron expressions don't support the "every other week" schedule directly.

You can try this workaround using two separate automation rules in Jira:

Create the first automation rule:


Schedule the rule to run every 4 weeks on Wednesdays, starting from a specific date.
Add the necessary actions to create the new issue as needed.


Create the second automation rule:

Schedule this rule to run every 4 weeks on Wednesdays, starting from the specific date plus 2 weeks (i. e. , the alternate Wednesday).
Add the same actions as the first rule to create the new issue.


By setting up these two separate automation rules with a 2-week offset, you'll have an issue created every other Wednesday, as desired.

 

Regards 

Oday

Michael Woffenden
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 18, 2023

Thanks for your reply.

However, I'm still confused. If we can't create an automation for "every 2 weeks", then how can we possibly do the same for "every 4 weeks?".

I am using Free Online Cron Expression Generator and Describer - FreeFormatter.com to generate the cron expressions.

Oday Rafeh
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 18, 2023

@Michael Woffenden , 

Apologies for the confusion. I realize that my previous response may not have been as clear as it should have been.

In Jira, you can use cron expressions to create rules that run every 4 weeks. 

Let me try to help you achieve that using the Free Online Cron Expression Generator:

In The Free Online Cron Expression Generator


Set the "Minute" field to the desired minute.


Set the "Hour" field to the desired hour.


Set the "Day of the Month" field to "? " (without quotes).


Set the "Month" field to "*".


Set the "Day of the Week" field to the desired day.


In the "Year" field, set the desired year or use "*" for every year.


Now, to create a rule that runs every 4 weeks, you need to adjust the "Day of the Month" field.

To do this, find the day of the month of the first Wednesday you want the rule to run.

For example, if the first Wednesday is the 7th day of the month, the rule should run on the 7th and then every 4 weeks after that.

To achieve this, set the "Day of the Month" field to "7/28" (without quotes).

Following this approach, you can create two separate automation rules with a 2-week offset between them, so you'll have an issue created every other Wednesday.

For the second rule, set the "Day of the Month" field to the day of the month corresponding to the alternate Wednesday (e. g. , "21/28").

I created some example of a cron expression that runs every 4 weeks at 10 AM on Wednesdays:


0 10 ? * WED#1/28


And here's an example of a cron expression that runs every 4 weeks at 10 AM on alternate Wednesdays:


0 10 ? * WED#3/28


By using what I mentioned above, you may be able to create issues every other Wednesday as desired.

 

Regards 

Oday

Michael Woffenden
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 18, 2023

Thanks again for your time and efforts! However I tried your expressions in the "Describe expression" feature, which in essence validates the expression.

Both expressions fail with the error

  • "'?' can only be specified for Day-of-Month or Day-of-Week."

screenshot_8065.jpg

So it seems we might be back to the drawing board?

Oday Rafeh
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 18, 2023

Can you try this Please :

0 10 1-7,29-31 * WED

0 10 15-21 * WED

And if this does not work then it's a corn expression error due to limitations that they have.

One possible solution we may have is to use a script or external scheduler that can trigger the Jira automation rule on specific dates.

You can use a Python script with the schedule library, which allows you to create more complex schedules than what cron expressions allow. for example:

Install the Python schedule library if you haven't already:

pip install schedule

Create a Python script with this content:


import schedule
import time
from datetime import datetime, timedelta

def create_issue_on_alternate_wednesdays():
# Replace with the actual API call to create a new issue in Jira
print("Creating issue on", datetime. now())

# Schedule the script to run on alternate Wednesdays
next_wednesday = datetime. now() + timedelta((2 - datetime. now(). weekday()) % 7)
schedule. every(2). weeks. at("10:00"). wednesday. at(next_wednesday. strftime('%Y-%m-%d')). do(create_issue_on_alternate_wednesdays)

while True:
schedule. run_pending()
time. sleep(60)
Replace the print statement with an actual API call to create a new issue in Jira. This script will run the create_issue_on_alternate_wednesdays() function every other Wednesday at 10:00 AM.

Remember this requires you to run the script on a server or machine that is always on and has access to Jira.

Regards

Oday

Michael Woffenden
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 19, 2023

Still getting errors, I agree that cron cannot handle this. 

We'll go the script route (we use powershell), or possibly we might be able to swing something within automation, since some date math can be done there.

Thanks for the ideas!

Oday Rafeh
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

@Michael Woffenden 

If you use PowerShell for scheduling tasks, you can create a script that will run on alternate Wednesdays.

function Create-IssueOnAlternateWednesdays {
# Replace with the actual API call to create a new issue in Jira
Write-Host "Creating issue on $(Get-Date)"
}

function Get-NextAlternateWednesday {
$today = Get-Date
$nextWednesday = $today.AddDays((2 - $today.DayOfWeek.value__) % 7)
if ($nextWednesday -lt $today) {
$nextWednesday = $nextWednesday.AddDays(7)
}
return $nextWednesday.AddDays(14) # Return alternate Wednesday
}

$nextRun = Get-NextAlternateWednesday
$action = { Create-IssueOnAlternateWednesdays }
$trigger = New-ScheduledTaskTrigger -Once -At $nextRun

$taskName = "Create Issue On Alternate Wednesdays"
$taskDescription = "A task to create a Jira issue on alternate Wednesdays"

Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Description $taskDescription

I hope this will help,  and happy to hear about the result. 

 

Regards 

Oday

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events