Can Jenkins schedule builds using different time zones? - jenkins

In some versions of crontab you can set the time zone for when the job should run like:
TZ=GMT
30 11 * * *
This would run at 11:30am GMT every day, even if the server was in some other time zone.
Even though Jenkins scheduling is based on cron, it doesn't seem to have this specific syntax. Is there some other way to do this in Jenkins?
Thanks

As Michael mentioned in his answer, this functionality was added. Here's an example:
TZ=Europe/Kiev
0 1 * * 5
That would run at 1:00 AM Ukraine time, once a week on Friday.
To get the names of time zones to use, you can use the column marked "TZ database name" in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

Looks like they added this in 2.60.2.

There's no way to do this in Jenkins. You could trigger the builds by calling a URL from cron though.
Edit: This has since been added; see the other answers.

Related

Jenkins bi-weekly build

How to setup jenkins job to only run biweekly at 8 AM in the morning.
Considering only the working days, Monday through Friday.
Basically running the build every second Friday.
You can use the following cron expression
0 8 8-14,22-28 * 5
The format explained looks as:
{Minute} {Hour} {DayOfMonth} {Month} {DayofWeek}
You might also want to check out Continuous Integration 101: How to Run JMeter With Jenkins for more information regarding how to set up Jenkins for JMeter tests execution.
This doesn't work, refer issue JENKINS-19756
However, a workaround that doesn't look good but works, check this answer.
Another workaround, that looks fine but works little erratically:
*0 7 1-7,15-21,29-31 * 1*
"all Mondays in 1st, 3rd and 5th week"
(error in this one: if there's a 5th week, it works its next week as well as its the first week of next month)

Jenkins - How to schedule job every period of days?

I tried to schedule a job run every 28 days but still not have solution yet.
Please help!
Thank!
As the documentation shows, using */X executes in intervals of X.
So, applying this to the "day of month" field, under "Build periodically", you could use the following to build at some consistent point in time once every 28 days:
H H */28 * 2
As an example, the 2 at the end signifies that the build should run on a Tuesday. Otherwise, it will probably build on whatever day of the week the current month started with.
I didn't try it yet so I may be wrong, but how about putting days as hours.
For example, if you want to run Jenkins job every 10 days, you schedule it to run every 240 hours.

Triggers executions Check repository

I want to have a trigger to see if there are any changes in the SVN every night from Monday to Friday at 22:00. I understand that I must put the following syntax "H 22 ** 1-5" is this correct?
At the root of this I have a question:
The company is in Spain, then what time is 22:00 Spanish or American?
Thank you very much and best regards.
You can set your timezone by logging into your instance and then going to JENKINS_URL/configure (Global properties).

Construct Quartz.Net Cron Expression for a requirement

I have a requirement to send email reminder to customers. I'm trying to trigger a Quartz job based on a datetime that is X weeks later after an event. In the Quartz job, I'm supposed to check for some condition whether it happened or not. If condition is false (e.g. no action from customer), I have to send another reminder Y weeks later. I then check again for the same condition, if false, I will send last reminder on a specific datetime that is known to me right at the start of this whole process.
Any idea how to construct the cron expression? Thanks
lyf
I suppose you're using C#, right?
You can use this cron:
var CronReminderExpression = string.Format("0 0 9 1/{0} * ? *", (PeriodicityLength*7).ToString());
where PeriodicityLength is the number of weeks. I am multiplying for 7 cause there's no proper expression for weeks or, at least, I haven't been able to find it.
You can find a cron expression builder here.
Quartz.net 2.0 supports a new trigger called CalendarIntervalTrigger. You can read more here.
You can chain jobs this way.

Discrepancy between System and Db times

I have a rails application and I store all time in UTC in the database for TimeZone differences' purposes. I also expire a record instead of deleting it by setting "effective_end_date" field in the table to current time. Then I use named scope as follows in the model:
named_scope :valid, :conditions => ['(effective_end_date IS NULL OR effective_end_date > ?)
AND (effective_start_date IS NULL OR effective_start_date < ?) ',Time.zone.now.gmtime, Time.zone.now.gmtime]
This seems to work fine on my Mac dev machine but once I move to production there seems to be discrepancy between the system time and the time which I'm not sure why!! Typing "date" command in Linux seems to give the right time. Looking at the production log file below:
sms parser(inparser) daemon is still running at Wed Jun 03 22:38:36 -0700 2009.
[4;35;1mUltrasmsin Load (0.5ms)ESC[0m ESC[0mSELECT * FROM `smsin` WHERE ((effective_end_date IS NULL OR effective_end_date > '2009-06-04 05:28:32')
AND (effective_start_date IS NULL OR effective_start_date < '2009-06-04 05:28:32') )
This the generated query from the following lines of code:
ActiveRecord::Base.logger.info "sms parser(inparser) daemon is still running at #{Time.now}.\n"
nonConvertedMsgs = Ultrasmsin.valid.find(:all)
The first command time displayed from "Time.now" is correct but the second time (fetched from the named scope) seems to be wrong!! (off by 10 minutes)
This is really puzzling me as I would think Time.zone.now.gmtime would just convert hours and wouldn't touch the minutes but it seems that hours are converted ok to GM Time but the minutes are off by 10 minutes!
Any ideas?
On your Mac development machine, everything - DBMS, Rails, browser - is probably running in a single time zone, and it is your time zone.
On your production machine, it is likely that something is running in a different time zone. How a DBMS handles differences between client time zone and the database time zone varies, depending on the DBMS. Some operate in the DBMS's time zone - whatever time zone was set in its environment when it was started. Some take into account the client's time zone. Sometimes, there is no easy way to find the client's time zone.
In general, time zones in the modern world are multiples of 1 hour off UTC. There are exceptions - both India (+05:30) and Newfoundland (-04:30) are a multiple of half an hour off UTC, and Nepal is on (+05:45). However, a malformed time zone setting could throw things off.
Also remember that the clocks on the client and server may not be synchronized to an atomic clock somewhere, so a ten minute drift could be due to the lack of SNTP (NTP) service on the machine.

Resources