Jenkins- how to schedule a build to run every 2 hours from 7 AM to 10PM on Monday through Friday - date

I'm looking for a way to run a Jenkins build every 2 hours, Monday through Friday only from 7 AM to 10PM. I got 7AM to 10PM and every 2 hours part down but how would I go about adding Monday through Friday to it?
Here is the schedule right now: H 07-22/2 * * *
If I add 1-5 to the above (1 for Monday and 5 for Friday), it gives me an error
" Invalid input: "H 07-22/2 * * * 1-5": line 1:16: expecting EOF,
found ' ' "
Please help me out.
Thanks.

You have too much element in your cron expression.
0 07-22/2 * * 1-5 instead of 0 07-22/2 * * * 1-5

Related

Coldfusion calculate seconds in days, hours, min

I want to convert seconds to days, hours and minutes
Currently, it works just for hours and minutes but not for days. Can you please support me tell me what I did wrong:
<cfscript>
seconds = '87400';
midnight = CreateTime(0,0,0);
time = DateAdd("s", seconds, variables.midnight);
date= xxxxxxxxxxxxxxxxxxxxx???
</cfscript>
<cfoutput>
#DateFormat(variables.date, 'd')# not working
#TimeFormat(variables.time, 'HH:mm')#
</cfoutput>
For the value 87400 the expected result is
1 Days, 0 hours, 16 minutes
If I take 94152 seconds it will be:
1 days, 3 hours, 22 minutes
The only issue i have is to get the correct days ... hours and minutes are diplayed but not the correct days
thank you for all the support
A simple way to calculate the intervals is by taking advantage of the modulus operator:
totalSeconds = 94152;
days = int(totalSeconds / 86400);
hours = totalSeconds / 3600 % 24;
minutes = totalSeconds / 60 % 60;
seconds = totalSeconds % 60;
For 94152 seconds, the results would be:
Interval
Value
DAYS
1
HOURS
2
MINUTES
9
SECONDS
12
TOTALSECONDS
94152
demo trycf.com
I understand from your question that you don't need to get a certain date and time along a timeline, but convert a total amount of seconds in days, hours and minutes. To do that you don't necessary need to use cfml time and date functions like CreateTime() or DateAdd(). You just may need these in order to get a reference point of time or date along a timeline, which doesn't seem to be the case, otherwise you would know the value of your starting date variable. Thus, you can solve this with plain rule of three. There may be simpler methods, so I'm posting an alternative only.
We know that:
60 seconds is equivalent to 1 minute
60 minutes is equivalent to 1 hour
24 hours is equivalent to 1 day
Thus, your calcualtion within cfml could be like so:
<cfscript>
//Constants for calculation
secondsPerDay= 60*60*24;
secondsPerHour= 60*60;
secondsPerMinute= 60;
//Seconds to convert
secondsTotal=87400;
// temp variable
secondsRemain= secondsTotal;
days= int( secondsRemain / secondsPerDay);
secondsRemain= secondsRemain - days * secondsPerDay;
hours= int( secondsRemain / secondsPerHour);
secondsRemain= secondsRemain - hours * secondsPerHour;
minutes= int( secondsRemain / secondsPerMinute);
secondsRemain= secondsRemain - minutes * secondsPerMinute;
writeoutput( "#secondsTotal# seconds are: #days# days, #hours# hours, #minutes# minutes and #secondsRemain# seconds." );
</cfscript>
That outputs:
87400 seconds are: 1 days, 0 hours, 16 minutes and 40 seconds.

Quartz schedule except specific time

Is it possible to create a CronExpression with: "fire every 5 min but not run at 00:05 and 00:10"?
org.quartz.CronScheduleBuilder.cronSchedule("0 0/5 * * * ?")
You will have to use two expressions:
0 15/5 0 * * ?
0 0/5 1-23 * * ?
The first expression is specific to 12 AM, the second is for the rest of the time.

Find how many sundays in a month asp classic

I am trying to use asp classic to find how many working days (mon - sat) are in the month and how many are left.
any help or pointers greatly appreciated!
Here's how you can find the number of Sundays in a month without iteration. Somebody posted a JavaScript solution a few months back and I ported it to VBScript:
Function GetSundaysInMonth(intMonth, intYear)
dtmStart = DateSerial(intYear, intMonth, 1)
intDays = Day(DateAdd("m", 1, dtmStart) - 1)
GetSundaysInMonth = Int((intDays + (Weekday(dtmStart) + 5) Mod 7) / 7)
End Function
So, your total work days would just be the number of days in the month minus the number of Sundays.
Edit:
As #Lankymart pointed out in the comments, the above function gives you the number of Sundays in the month but it doesn't tell you how many are left.
Here's another version that does just that. Pass in any date and it will tell you how many Sundays are left in the month starting with that date. If you want to know how many Sundays are in a full month, just pass in the first day of the month (e.g., DateSerial(2014, 8, 1)).
Function GetSundaysRemainingInMonth(dtmStart)
intDays = Day(DateSerial(Year(dtmStart), Month(dtmStart) + 1, 1) - 1)
intDays = intDays - Day(dtmStart) + 1
GetSundaysRemainingInMonth = Int((intDays + (Weekday(dtmStart) + 5) Mod 7) / 7)
End Function
Edit 2:
#Cheran Shunmugavel was interested in some specifics about how this works. First, I just want to restate that I didn't develop this method originally. I just ported it to VBScript and tailored it to the OP's requirement (Sundays).
Imagine a February during a leap year. We have 29 days during the month. We know from the start that we have four full weeks, so each weekday will be represented at least four times. But that still leaves one addition day that's unaccounted for (29 Mod 7 = 1). How do we know if we get an extra Sunday from that one day? Well, in this case, it's pretty simple. Only if our start date is a Sunday can we count an extra Sunday for the month.
What if the month has 30 days? Then we have two extra days to account for. In that case, the start date can be a Saturday or a Sunday and we can count an extra Sunday for the month. And so it goes. So we can see that if we're X additional days within an upcoming Sunday, we can count an extra Sunday.
Let's put this in tabular form:
Addl Days Needed
Day To Count Sunday
---------- ----------------
Sunday 1
Saturday 2
Friday 3
Thursday 4
Wednesday 5
Tuesday 6
Monday 7
So what we need is a formula that we can apply to these situations so that they all result in the same value. We'll need to assign some value to each day and combine that value with the number of addition days needed for Sunday to count. Seems reasonable that if we assign an inverse value to the weekdays and add that to the number of additional days, we can get the same result.
Addl Days Needed Value Assigned
Day To Count Sunday To Weekday Sum
---------- ---------------- -------------- ---
Sunday 1 6 7
Saturday 2 5 7
Friday 3 4 7
Thursday 4 3 7
Wednesday 5 2 7
Tuesday 6 1 7
Monday 7 0 7
So, if weekday_value + addl_days = 7 then we count an extra Sunday. (We'll divide this by 7 later to give us 1 additional Sunday). But how do we assign the values we want to the weekdays? Well, VBScript's Weekday() function already does this but, unfortunately, it doesn't use the values we need by default (it uses 1 for Sunday through 7 for Saturday). We could change the way Weekday() works by using the second param, or we could just use a Mod(). This is where the + 5 Mod 7 comes in. If we take the Weekday() value and add 5, then mod that by 7, we get the values we need.
Day Weekday() +5 Mod 7
---------- --------- -- -----
Sunday 1 6 6
Saturday 7 12 5
Friday 6 11 4
Thursday 5 10 3
Wednesday 4 9 2
Tuesday 3 8 1
Monday 2 7 0
That's how the + 5 Mod 7 was determined. And, with that solved, the rest is easy(er)!
#Zam is on the right track you need to use WeekDay() function, here is a basic idea of how to script it;
<%
Dim month_start, month_end, currentdate, dayofmonth
Dim num_weekdays, num_past, num_future
Dim msg
'This can be configured how you like even use Date().
month_start = CDate("01/08/2014")
month_end = DateAdd("d", -1, DateAdd("m", 1, month_start))
msgbox(Day(month_end))
For dayofmonth = 1 To Day(month_end)
currentdate = CDate(DateAdd("d", dayofmonth, month_start))
'Only ignore Sundays
If WeekDay(currentdate) <> vbSunday Then
num_weekdays = num_weekdays + 1
If currentdate <= Date() Then
num_past = num_past + 1
Else
num_future = num_future + 1
End If
End If
Next
msg = ""
msg = msg & "Start: " & month_start & "<br />"
msg = msg & "End: " & month_end & "<br />"
msg = msg & "Number of Weekdays: " & num_weekdays & "<br />"
msg = msg & "Weekdays Past: " & num_past & "<br />"
msg = msg & "Weekdays Future: " & num_future & "<br />"
Response.Write msg
%>
How about using "The Weekday function returns a number between 1 and 7, that represents the day of the week." ?

Multiple 'nth' weekday of month in a single quartz cron expression

I'm trying to write a cron expression for quartz that runs hourly everyday except every second Saturday of the month.
So, by using the '#' notation, I was trying to write the expression like:
0 0 * ? * SUN-FRI,SAT#1,SAT#3,SAT#4,SAT#5
This expression is not working properly. Also, quartz is not complaining about the cron format (quartz usually complains about cron expressions when they are wrong).
So I did some other experiments today. So, today is the third Thursday of the month, I was playing around with THU#N notation, and that's what I've found so far (I changed my expression to minute to make it easier for experimenting):
0 * * ? * SUN-FRI,SAT#1,SAT#3,SAT#4,SAT#5: not triggered
0 * * ? * THU#3: triggered
0 * * ? * THU#3,THU#4: not triggered
0 * * ? * THU#2,THU#3: triggered
I know I can simply split this into 4 additional expression but in my real scenario I have tons of expressions to change and this would increase my expression list to something 5 times longer.
In a brief: Does anyone knows how to condense these:
0 0 * ? * SUN-FRI / 0 0 * ? * SAT#1 / 0 0 * ? * SAT#3 / 0 0 * ? * SAT#4 / 0 0 * ? * SAT#5
...into a single cron expression?
Note: I'm using quartz scheduler 1.5 (I know, I know... pretty outdated)

Cronexpression to exclude hours of a specific day

Is it possible to create a CronExpression with:
"fire every day every 20min but not on Saturday between 10:00 and 14:00"?
Something like "0 0/20 * ? * MON-SAT" is clear, but it is not the same...
You will have to use two expressions; One for saturdays, one for all other days:
0 0/20 * * * SUN-FRI command
0 0/20 0-9,14-23 * * SAT command