Create a TRICKY Scheduled trigger using CRON expressions
Asked by Nahuel Logghe:

Hello everyone,

**I'm looking to set up a scheduled task** that runs **every 5 minutes** , but it should only activate **outside of standard working hours**. Our working hours are from 8 AM to 5 PM CET, Monday to Friday. From what I understand, achieving this with just one CRON expression isn't feasible, right?

Could anyone suggest an alternative approach for implementing this? How can I accomplish this task?


Answers:
author: Nahuel Logghe
body: Is it possible to use the trigger every x minutes, regardless of time and day, and use IF conditions to add the other variables?

are there any smart values I can use for this?

comments: author: Kenneth Henseler
body: That was going to be next suggestion, but would need to test this to know for sure. Thought you might be able to use a date comparison, but Atlassian's Business Day is slightly different than yours: [Examples of using smart values with dates \| Cloud automation Cloud \| Atlassian Support](https://support.atlassian.com/cloud-automation/docs/examples-of-using-smart-values-with-dates/#Calculating-business-days).


author: Nahuel Logghe
body: I created a "solution", I'm just unsure if it is working as I intended. Give me your opinion, please.

I'm using a branch rule to compare each variable, using "now.format" for the day of the week and "now.hour" to check the time. Like this:

Branch:

For: Current Issue

Check if : {{now.format("EEEE")}} equal "Saturday"

Then: Send email

Branch:

For: Current Issue

Check if : {{now.format("EEEE")}} equal "Sunday"

Then: Send email

Branch:

For: Current Issue

Check if : {{now.hour}} greater than 17

Then: Send email

So basically if it's not Saturday it will check if it's Sunday, and if it's not Sunday either it will check the time, etc.**Did I do this properly?**


author: Nahuel Logghe
body: I made a mistake, I'm actually using {{now.dayOfWeekName}} instead of {{now.format("EEEE")}}.

I'm unsure if it works though


author: Kenneth Henseler
body: Your logic appears to be correct, based on your requirements. Test it and see! The Send Email action might create a bit of noise while you're testing, but if that's acceptable, go for it. You might consider setting the action to just comment on an existing issue too. Either way, put it to test and make sure it works as intended. Good work!


author: Nahuel Logghe
body: Thanks for the help and support. I'll post again to show if it worked


author: Kenneth Henseler
body: To run a cron job every 5 minutes, excluding business hours, you can use the following expression:

```
*/5 17-7 * * 1-5
```

Explanation:

\*/5: This means every 5 minutes.  
17-7: Specifies the hours from 5 PM to 7:59 AM (outside business hours).  
\*: Represents all days of the month.  
\*: Represents all months.  
1-5: Refers to Monday through Friday (business days).  
So, the cron job will execute every 5 minutes between 5 PM and 8 AM on weekdays (Monday to Friday).

comments: author: Nahuel Logghe
body: Hi Kenneth,

thanks for the answer. I don't think I have explained myself correctly.

What I need is for it to run outside of business hours Monday through Friday. But on Saturdays and Sundays it has to run all day, since weekend is also out of business hours.

Also, cron does not allow expressions like 17-7 that cross from one day to the next. The allowed values are 0-23, hence my dilemma (or at least one of them)

So far I come out with 3 expressions, but I cannot run them in the same rule, can I? That would be the best because I don't want to have 3 rules for the same alert:

\*/5 0-8 \* \* 1-5 -\> every 5th minute, every hour from 0 through 8hs on every day-of-week from Monday through Friday.

\*/5 17-23 \* \* 1-5 -\> This one schedules the task to run every 5 minutes from 17 to 23hs on Monday to Friday.

\*/5 \* \* \* 6,0 -\> Weekends all day.

Can I run these 3 cron expressions on one rule? Or somewhat combine them?


Tags: automation

cloud

cron

jira-service-management

jira-service-management-cloud

trigger