How to make Cloud Scheduler to run on specific dates? - google-cloud-run

I have written a script on cloud run.. And would like to execute it twice or thrice some days in the future.
Lets say today is 19/Jan/2023... Now how do I set Cloud Scheduler to run my cloud run on only 13/Mar/2023, 18/June/2023 and 19/June/2023....

You can create a Cloud Scheduler jobs by following this documentation on creating a Cloud Scheduler job. Please make sure to follow the proper cron job format.
I also found this crontab guru link wherein you can easily create a cron job. Examples below are based on the dates that you provided:
0 0 13 3 * - 13/Mar/2023
0 0 18 6 * - 18/June/2023
0 0 19 6 * - 19/June/2023
If you have multiple schedules that won't fall on the same time/month/day, you need to create a separate job as the cron job will read the schedule continuously. For example, if you merge the months and dates altogether in a single schedule:
0 0 13,18,19 3,6 *
This would be read by Cloud Scheduler as:
At 00:00 on day-of-month 13, 18, and 19 in March and June.
next at 2023-03-13 00:00:00
then at 2023-03-18 00:00:00
then at 2023-03-19 00:00:00
then at 2023-06-13 00:00:00
then at 2023-06-18 00:00:00
Meaning that your job will be executed on the dates that you did not specify above.
You can merge time/month/date like this:
0 0 13 3 * - 13/Mar/2023
0 0 18,19 6 * - 18 and 19/June/2023

Related

How to set two different scheduler for single Jenkins job

I just want to run the job twice per week. Every Sunday 11 PM and every Friday 11 pm I just want to trigger the job automatically. I successfully implemented for one scheduler but not sure how to use two in single .
Sunday scheduler :
H 11 * * 0
Friday scheduler:
H 11 * * 6
For scheduling the job below pattern need to be followed:-
0 - Sun Sunday
1 - Mon Monday
2 - Tue Tuesday
3 - Wed Wednesday
4 - Thu Thursday
5 - Fri Friday
6 - Sat Saturday
7 - Sun Sunday
For your case you can follow the below:-
0 23 * * 0,5
You better understanding of "H" in Jobs Scheduler follow this:
Maybe something like this. Note there's a couple changes from your example, changed 11 to 23, 11 is 11am, 23 is 11pm and using 5 instead of 6 for Friday.
H 23 * * 0,5
But note with the "H" it isn't going to run at exactly 11pm, from the Jenkins docs:
The H symbol can be thought of as a random value over a range, but it
actually is a hash of the job name, not a random function, so that the
value remains stable for any given project.
If you want it to run closer to 11pm, maybe something like this
H(1-5) 23 * * 0,5

Schedule job to run periodically

I am trying to run Jenkins job everyday at 10 AM and 10 PM . How do i do that?
Currently i use the below to run at 12 AM and 12 PM . Am not aware how to change it.
0 0-23/12 * * *
Its difficult to acheive it with just a single crontab entry, what you can do is to have a 2 crontab entry like below :-
for job which you want to run daily at 10 AM :-
0 10 * * *
And for 10 PM job 0 22 * * *.
Here first entry denotes the minute, second denotes the hour and then day,month and week.
Just click the "?" icon to the right of the "Schedule" field, and you'll see a detailed explanation of the syntax available there.
If you want it to run at 12am and 12pm, I would guess you would just do this:
0 0,12 * * *
Suppose you want to run a jenkins job at 4:30 AM , monday to saturday, then you can use below script under your jenkins build trigger:
30 04 * * 1-6
1-6 denotes monday to saturday
Coming back to your question, you can configure 2 entries under your build trigger to run Jenkins job everyday at 10 AM and 10 PM in jenkins as shown below:
00 10 * * 1-7
00 22 * * 1-7

How to schedule a Jenkins job each 15 minutes [duplicate]

This question already has an answer here:
Jenkins Build Periodically - Schedule
(1 answer)
Closed 6 years ago.
I need to schedule a jenkins job each 15 minutes.
Currently i'm using the Build periodically feature but that enables me to schedule the job once in 1 hour maximum.
What i got now is:
15 * * * * is running the job HOURLY (each XX:15)
15 0 * * * is running the job DAILY on 00:15
What is the right cron-expression that will run the job every 15 minutes?
To run the job at a regular interval of 15 minutes you have to write it like below:
*/15 * * * * - Will run at every 15 minutes (may be at XX:01,XX:16,XX:31 ..)
Where */15 specifies no matter whatever is Hour (H) run it at 15 every minutes.

Why Jenkins does not run a job as scheduled?

I have this 'Build periodically' option with the following 'Schedule':
H 6,13 * * *
Meaning that I want this job to be run everyday at 6:00 and 13:00.
I noticed that it does not run at the specified time but 34 minutes later instead. These are the last builts:
#3​06 12-feb-2015 6:34
#3​05 11-feb-2015 13:34
#3​04 11-feb-2015 6:34
#3​03 10-feb-2015 13:34
#3​02 10-feb-2015 6:34
Plus, under the 'Schedule' text area there is a note saying:
Would last have run at Thursday, February 12, 2015 6:34:42 AM CET;
would next run at Thursday, February 12, 2015 1:34:42 PM CET.
This is not a big deal, but it is a bit annoying that there is a 34 minutes delay. Does anyone know why this is happening and how to solve it (without manually adding this delay on the schedule)?
Replace the H by 0 to have 6:00.
The H is intended to distribute tasks over the hour, so not all Jenkins tasks start exactly at 06:00 etc. (so it is not a delay, but a different way of scheduling).
Two different tasks scheduled both at H 13 * * * will start at different minutes but still between 13:00 and 13:59:59, so they won't make your system too slow. The H value is the job specific hash value, so it will still be a constant within the job, but different between jobs.

Jenkins scheduled job

Is possible to scheduled a jenkins job to repeat a task every 45 min in a time interval?
Example (Repeat the job every 45 min as many times as possible since 10:00 am to 16:00 pm) - result would be 8 executions.
Thanks!!!
Yes. In the job configuration page, search for the section Build Triggers. In this section, enable Build periodically and put the following lines:
0,45 0-23/3 * * *
30 1-23/3 * * *
15 2-23/3 * * *
Reference: Is the following cron expression means every 45 minutes?
Explanation:
0,45 means to run at 0 mins and 45 mins for ex. 2 am and 2:45 am
0-23/3 in hour field means that a particular activity has to be performed every 3 hrs. In this case, it means 0, 3, 6, 9,... till 21 hrs (or 2100 hrs). Similarly for others.
So, first line i.e., 0,45 0-23/3 * * * takes care of 0000 hrs and 0045 hrs. Next time (+45 mins) will be 0130 hrs which will be taken care by 30 1-23/3 * * * and so on.
You can check the cron format details here: http://en.wikipedia.org/wiki/Cron

Resources