Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Cron Job to run every 6 hours Mon to Fri

Mario Coluzzi August 31, 2024

Hello,

 

Anyone can help me in how to create a Cron Job to run an automation exmple: every 6 hours at 10:00 AM from Monday to Friday

This article is not clear in the matter not helpful in how to achieve that: https://support.atlassian.com/jira-software-cloud/docs/manage-filters/

Cheers

3 answers

0 votes
Mario Coluzzi September 1, 2024

Hi @Manoj Gangwar I did try something similar to your expression
0 10/6 * ? * MON-FRI but I am unsure whether this works based on https://support.atlassian.com/jira-software-cloud/docs/manage-filters/

Hi @Trudy Claspill every 6 hours like a normal Cron Job would do: 0 */6 * * Mon-Fri see https://crontab.guru/#0_*/6_*_*_Mon-Fri 

You option to use ELSE IF is a nice solution but TBH I should not go through the ordeal in creating an automation to automate the Cron Jobs. My automations are enough complex, although your option is a feasible option should I not find a solution

0 votes
Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2024

You may test the below corn expression.

0 10/6 * ? * MON-FRI

 

Mario Coluzzi September 3, 2024

Hi @Manoj Gangwar 

That expressions runs the automation every 6 minutes. Tested it 

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 31, 2024

Hello @Mario Coluzzi 

Note that I have not tested this solution as that would require the passage of days of time.

I recommend you use a Schedule trigger like this:

schedule-trigger.png

That will start the rule running at 10 am (Los Angeles time) on Monday. The lower portion will run the rule every 6 hours.

You then need to add a condition to check the current time when the rule is running to see if it is during the time you don't want it to run. You didn't specify the latest time on Friday when the rule could run, but running every six hours means that it could run at 4 am, 10 am, 4 pm, and 10 pm, So let us say that the latest run can be the 10 pm run.

You'll need to use an IF-ELSE block so that you can apply multiple conditions to see if it is in the black out period and proceed with the rest of your rule if it is not.

In the first IF block you will check if the current day is Saturday or Sunday. If it is you don't want to run the rule.

IF-Sat.png

 

if-sun.png

 

The smart value to extract the day of week from the current time, with a conversion to relevant timezone, is:

{{now.convertToTimeZone("America/Los_Angeles").format("EEE")}}

 

In this case you don't want to run the main actions of the rule, but you must run some action. So add a Log action to log a message of your choice to the rule execution audit log.

Insert an Else-If to check for the next blackout condition; is it Monday and before 10 am.

IF-MON-1.png

IF-MON-2.png

The smart value to get the current hour of the day, with the conversion to the relevant timezone, is:

{{now.convertToTimeZone("America/Los_Angeles").format("k")}}

Again, since this is within the blackout you don't want to execute the main actions of your rule but you must execute some action. So add another Log action..

Lastly add the last Else after which you add the actions you want to execute for your automation.

rule-1.png

rule-2.png

 

 

 

 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2024

@Mario Coluzzi

Can you clarify what you mean by your timing statement ?

Every 6 hours at 10 am Monday through Friday

Does that mean starting at 10 am each day a and ending at midnight each day, so that there would be 3 runs each day?

Or does that mean starting at 10 am on Monday and running every 6 hours continuously until a specific time on Friday?

My answer applies to the latter.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 3, 2024

Hi @Trudy Claspill every 6 hours like a normal Cron Job would do: 0 */6 * * Mon-Fri see https://crontab.guru/#0_*/6_*_*_Mon-Fri 

You option to use ELSE IF is a nice solution but TBH I should not go through the ordeal in creating an automation to automate the Cron Jobs. My automations are enough complex, although your option is a feasible option should I not find a solution

Hello @Mario Coluzzi 

In your post you mentioned that you wanted the cron job to start at 10 am on Monday. That is the point I am trying to clarify.

Do you want the job to start at 10 am Monday and then run every 6 hours continuously through Friday?

Or do you want the first run of the job to be at 10 am each day, Monday through Friday?

 

*/6 for the Hours and MON-FRI for the days of week would start at 00:00 on Monday and run every six hour through 24:00 on Friday.

If you use 10/6 and MON-FRI then the job will start at 10:00 am each day and run every six hours until 23:00 that day.

If either of the two options above matches your needs then you don't need the If-Else blocks I described.

 

If you need something that starts at 10 am on Monday and then runs continuously every 6 hours through Friday then your options are:

  1. The If-Else structure I suggested.
  2. Multiple rules with different cron settings to match the every 6-hour pattern you want:
    Monday: 10 am, 4 pm, 10 pm
    Tuesday-Friday: 4 am, 10 am, 4 pm, 10 pm

    10/6 MON
    4/6 TUE-FRI

Mario Coluzzi September 3, 2024

Hi @Trudy Claspill 

I did put as @Manoj Gangwar said:  0 10/6 * ? * MON-FRI the automation runs every 6 minutes. I did test it. See logs timestamp dump below

It does not matter if the automation start running at 10:00 or at 15:20 or at 23:11 It has to run every 6 hours between weekdays of Mon to Fri.

If it can start at 00:01 even better

 

03/09/24, 10:22:29 pm

03/09/24, 10:17:56 pm

03/09/24, 10:14:01 pm

03/09/24, 10:00:31 pm

03/09/24, 09:54:29 pm

03/09/24, 09:48:25 pm

03/09/24, 09:42:44 pm

03/09/24, 09:36:29 pm

03/09/24, 09:28:54 pm

03/09/24, 09:22:55 pm

03/09/24, 09:17:17 pm

03/09/24, 09:11:15 pm

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 3, 2024

The cron statement needs to include a Seconds element in the first position.

* 1 0/6 * * MON-FRI

Any Second,  minute 1 of the hour, starting with hour 0 then every 6 hours, any day of the month, any month of the year, on the days of the week Monday through Friday.

Should work, but I haven't had a chance to test it.

Mario Coluzzi September 4, 2024

Hi @Trudy Claspill 

It does work! I put in place and it does the job.

Although Jira complains on wrong formatting, therefore the correct one is:

 

* 1 0/6 ? * MON-FRI

 

A bit tricky one but in the end we crack it

Thank you.

M

05/09/24, 12:04:28 am - Scheduled for - NO ACTIONS PERFORMED

04/09/24, 06:04:07 pm - Scheduled for - SUCCESS

Like Trudy Claspill likes this
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 4, 2024

Wonderful!

If our responses were helpful please consider clicking on the Accept Answer buttons to mark your Question as Solved.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events