Getting TFS Build Schedules - tfs

I am trying to write a query for all builds, but failed to understand the column [ScheduleTime] in the table [tbl_Schedule].
SELECT bd.DefinitionName 'Name', s.ScheduleTime 'ScheduleTime', s.ScheduleTime/1800 'Hour'
FROM [TFS_FTPDev].[dbo].[tbl_Schedule] s
inner join [TFS_FTPDev].[dbo].[tbl_BuildDefinition] bd on
bd.[DefinitionId]=s.[DefinitionId]
where ContinuousIntegrationType in (8,16)
order by s.ScheduleTime asc
If I divide by 3600, I get a sensible data, but it is not valid for all my builds... i.e. Build1 and build2 are scheduled for 13:00 for some days....
name ScheduleTime Hour
build1 43200 12
build2 43200 12
build3 68400 19
build4 77400 21.30
build5 79200 22
build6 82800 23
build7 84600 23.30
build8 84600 23.30
build9 84600 23.30
and the mapping is:
when 84600 then 23.30
when 79200 then 22
when 77400 then 21.30
when 68400 then 19
when 43200 then 12
UPDATE: [Using TFS API]
And this is the API results for a manually triggered/scheduled build...
And this is the subset of results

Have you taken a look at the QueryBuilds method in the TFS Build API instead of reading from the database (which is unsupported)?

The documentation for ISchedule.StartTime Property says
Gets or sets the time as the number of seconds past midnight
So you should divide by 3600 to get the starting hour, the remainder divided by 60 is the starting minute within the hour.
Am I missing anything?

I'm not really sure what you are asking but if you use 3,600 (60 seconds x 60 minutes) you get values as expected.
00:00 = 3600
00:30 = 5400
04:00 = 14400
05:30 = 19800
23:00 = 82800
Your question regarding why some have schedules while being manual builds can be replicated by:
create a build definition
Schedule it
Clone the build definition
Rename it and before saving change the trigger type
Even though this build has never been scheduled it still contains a scheduled time
I would therefore suggest the builds that you are enquiring about have actually been cloned from another build and then the meta data changed, scheduled time seems not be cleared when a build is changed from scheduled to Non Scheduled. either that or at some point during their history they have had a scheduled time set, which has since been changed

Related

Jenkins build not getting triggered on scheduled time

I want to schedule a build every day at a particular time say 4pm.
And hence I have set up the build periodically to :
H 16 * * *
I am noticing that the build either doesn't get triggered at the scheduled time or else gets triggered at a random time , ( 4 hours prior to scheduled build)
I want to understand how scheduling works for the build to understand why is it not triggering build at the intended time.
I suspected that master node would be in a timezone other than what I want but that is also not the case.
Inspite of setting timezone as below:
TZ=America/Los_Angeles
H 16 * * *

Jenkins triggering job twice

I have a job that is configured to schedule and run a job periodically using the following schedule:
01 14 * * 1-5
For some reason, the job is triggering twice every day at the same time. I cannot work out why it is triggering twice. I suspect two possible issues:
The Day of Month (DOM) and Day of Week (DOW) is contradicting
The fact that there are multiple spaces after each column might be confusing Jenkins
Questions
Am i correct that the above says the job should run daily at 14:01 UTC?
What is the significance of the last field? If the fourth field (day of month) specifies * meaning every day of the month, what would be the purpose of the last field (Day of Week)?
What would be the behaviour if i had something like this (where DOM and DOW contradict)
01 14 * * 5

Meaning of H/5 in cron Jenkins

I have a job with as cron:
5 3,21 * * 1-5
This will run my job at 03:05AM and 09:05PM. Now I read it's a best practice to use H.
I try:
H/5 3,21 * * 1-5
What is the meaning now? Will this schedule a build in a range of 5 minutes or 5 minutes after 3AM and 21PM?
The H will take a numeric hash of the Job name and use this to ensure that different jobs with the same cron settings do not all trigger at the same time. This is a form of Scheduling Jitter
H/5 in the first field means Every five minutes starting at some time between 0 and 4 minutes past the hour
So H/5 3,21 * * 1-5
is Every five minutes between 03:00 and 03:59 and then between 21:00 and 21:59 on Mon -> Fri but starting at some 'random' time between 03:00 and 03:04 and then the same number of minutes after 21:00
If you want to run once per hour between 03:00-03:59 and 21:00-21:59 on Mon -> Fri, you can use H 3,21 * * 1-5 where H will be replaced by some number between 0-59 depending on job name.
The user interface will tell you when the job will last have triggered and will next trigger

Jenkins Build Periodically - Does it support Multiple Schedules?

Does Jenkins Build Periodically support having 2 different schedules for a job at the same time?
H 22 * 7-12 1-5
H 20 20 1-6 *
The above is just an example. What it intends to do is,
H 22 * 7-12 1-5 : Run the job for last 6 months of a year every weekday around 10PM.
H 20 20 1-6 * : Run the same job for 1st 6 months of a year once a month on the 20th day around 8PM
UPDATE:
Trying this now at 6.40 PM
H 10 * * *
H 15 * * *
Gives,
Would last have run at Thursday, June 15, 2017 3:45:32 PM; would next run at Friday, June 16, 2017 10:59:32 AM.
Which seems to suggest both schedules were accepted by Jenkins!
The Parameterized Scheduler plugin also adds the ability to have different parameters per schedule, so if you have something like a backup job that you want to run in multiple environments, you can have it scheduled three times in one night, once for each environment.
But otherwise, if you just need to have more than one schedule, adding one schedule per line should work just fine (with no extra plugins).

How do I schedule jobs in Jenkins?

I added a new job in Jenkins, which I want to schedule periodically.
From Configure job, I am checking the "Build Periodically" checkbox and in the Schedule text field added the expression:
15 13 * * *
But it does not run at the scheduled time.
Is it the correct procedure to schedule a job?
The job should run at 4:20 AM, but it is not running.
By setting the schedule period to 15 13 * * * you tell Jenkins to schedule the build every day of every month of every year at the 15th minute of the 13th hour of the day.
Jenkins used a cron expression, and the different fields are:
MINUTES Minutes in one hour (0-59)
HOURS Hours in one day (0-23)
DAYMONTH Day in a month (1-31)
MONTH Month in a year (1-12)
DAYWEEK Day of the week (0-7) where 0 and 7 are sunday
If you want to schedule your build every 5 minutes, this will do the job : */5 * * * *
If you want to schedule your build every day at 8h00, this will do the job : 0 8 * * *
For the past few versions (2014), Jenkins have a new parameter, H (extract from the Jenkins code documentation):
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible.
For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast, using H H * * * would still execute each job once a day, but not all at the same time, better using limited resources.
Note also that:
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.
More example of using 'H'
The format is as follows:
MINUTE (0-59), HOUR (0-23), DAY (1-31), MONTH (1-12), DAY OF THE WEEK (0-6)
The letter H, representing the word Hash can be inserted instead of any of the values. It will calculate the parameter based on the hash code of you project name.
This is so that if you are building several projects on your build machine at the same time, let’s say midnight each day, they do not all start their build execution at the same time. Each project starts its execution at a different minute depending on its hash code.
You can also specify the value to be between numbers, i.e. H(0,30) will return the hash code of the project where the possible hashes are 0-30.
Examples:
Start build daily at 08:30 in the morning, Monday - Friday: 30 08 * * 1-5
Weekday daily build twice a day, at lunchtime 12:00 and midnight 00:00, Sunday to Thursday: 00 0,12 * * 0-4
Start build daily in the late afternoon between 4:00 p.m. - 4:59 p.m. or 16:00 -16:59 depending on the projects hash: H 16 * * 1-5
Start build at midnight: #midnight or start build at midnight, every Saturday: 59 23 * * 6
Every first of every month between 2:00 a.m. - 02:30 a.m.: H(0,30) 02 01 * *
Jenkins lets you set up multiple times, separated by line breaks.
If you need it to build daily at 7 am, along with every Sunday at 4 pm, the below works well.
H 7 * * *
H 16 * * 0
*/5 * * * * means every 5 minutes
5 * * * * means the 5th minute of every hour
The steps for scheduling jobs in Jenkins:
click on "Configure" of the job requirement
scroll down to "Build Triggers" - subtitle
Click on the checkBox of Build periodically
Add time schedule in the Schedule field, for example: #midnight
Note: under the schedule field, can see the last and the next date-time run.
Jenkins also supports predefined aliases to schedule build:
#hourly, #daily, #weekly, #monthly, #midnight
#hourly --> Build every hour at the beginning of the hour --> 0 * * * *
#daily, #midnight --> Build every day at midnight --> 0 0 * * *
#weekly --> Build every week at midnight on Sunday morning --> 0 0 * * 0
#monthly --> Build every month at midnight of the first day of the month --> 0 0 1 * *
Another example, How to run only on a specific day of the week:
# Every Sunday at 19:00
0 19 * * 0
The number at the end is the day of the week according to the following list:
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
If you are interested in how many days a week you can add a comma like this:
# Monday, Wednesday and Friday:
0 19 * * 1,3,5
Jenkins Job Scheduling Syntax
First, let’s look at the Jenkins job scheduling configuration. It looks a lot like Linux’s cron syntax, but you don’t have to be familiar with command line Linux to figure it out.
A scheduling entry consists of five whitespace-separated fields. You can schedule a job for more than one time by adding more than one entry.
Screenshot
Each field can contain an exact value or use a set of special expressions:
The familiar asterisk * indicates all valid values. So, a job that runs every day has a * in the third field.
A dash separates ranges of values. For example, a job that runs every hour from 9:00 a.m. to 5:00 p.m. would have 9-17 in the second field.
Intervals are specified with a slash /. A job that runs every 15 minutes has H/15 in the first field. Note that the H in the first field has a special meaning. If you wanted a job to run every 15 minutes, you could configure it as 0/15, which would make it run at the start of every hour. However, if you configure too many jobs this way, you can overload your Jenkins controller. Ultimately, the H tells Jenkins to pick a minute based on a hash of the job name.
Finally, you can specify multiple values with a comma. So, a job that runs Monday, Wednesday, and Friday would have 1,3,5 in the fifth field.
Jenkins provides a few examples in their help section for scheduling.
Every fifteen minutes (perhaps at :07, :22, :37, :52):
H/15 * * * *
Every ten minutes in the first half of every hour (three times,
perhaps at :04, :14, :24):
H(0-29)/10 * * * *
Once every two hours at 45 minutes past the hour starting at 9:45 AM
and finishing at 3:45 PM every weekday:
45 9-16/2 * * 1-5
Once in every two hour slot between 8 AM and 4 PM every weekday
(perhaps at 9:38 AM, 11:38 AM, 1:38 PM, 3:38 PM):
H H(8-15)/2 * * 1-5
Once a day on the 1st and 15th of every month except December:
H H 1,15 1-11 *
Jenkins also has a set of aliases that makes using common intervals easier.
Screenshot of table
To schedule a cron job every 5 minutes, you need to define the cron settings like this:
*/5 * * * *
Try this.
20 4 * * *
Check the below Screenshot
Referred URL - https://www.lenar.io/jenkins-schedule-build-periodically/
Try using 0 8 * * *. It should work
Jenkins uses Cron format on scheduling.
You can refer this link for more detailhttps://en.wikipedia.org/wiki/Cron.
One more thing, Jenkins provide us a very useful preview. Please take a look on the screenshot.
I hope this help. Thanks

Resources