如何在 Jenkins 中安排构建?
如何安排 Jenkins 构建,使其只能在每天的特定时间进行构建?
例如,从下午 4 点开始,
0 16 1-7 * *
我理解为“从星期一到星期日,每月 0 分钟,下午 4 点”,但是它每分钟都会构建:(
如果有任何建议,我将不胜感激。谢谢!
How do I schedule a Jenkins build such that it would be able to build only at specific hours every day?
For example to start at 4 PM
0 16 1-7 * *
I understand that as, "at 0 minutes, at 4 o'clock PM, from Monday to Sunday, every month", however it builds every minute :(
I would be grateful for any advice. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
在 Jenkins 中,我们的格式如下:
In Jenkins , we have the format is as:
Jenkins 使用 Cron 表达式。
您只需输入
@hourly
即可安排每小时构建。Jenkins uses Cron Expressions.
You can simply schedule hourly builds by just typing
@hourly
.周一至周日下午 4 点试试这个
您可以在 Jenkins 下的“定期构建”中查看配置时显示的描述消息。(请参阅下面给出的屏幕截图)
屏幕截图
“2019 年 11 月 18 日星期一 4:00:05 PM IST”时间中的秒指的是我们的当前系统秒数。
Try this for 4 PM from Monday to Sunday
You can check the description messgage displayed while you configuring in "Build periodically' under Jenkins. (Refer the screenshot given below)
Screenshot
The seconds in the time " Monday, November 18, 2019 4:00:05 PM IST" refers to our current system seconds.
更新: 请阅读其他答案和评论,因为它们包含我第一次回答这个问题时所不知道的更多信息(例如哈希函数)。
根据 Jenkins 的说法计划任务的自己的帮助(“?”按钮),指定了 5 个字段:
我只是试图在下午 4:42(我的大约当地时间)启动一份工作,它与以下内容一起工作,尽管多花了大约 30 秒:
如果您想要多次,我认为以下应该工作时间:
每天下午 4 点、6 点、8 点和 10 点。
Update: please read the other answers and comments as they contain more info (e.g., hash functions) that I did not know when I first answered this question.
According to Jenkins' own help (the "?" button) for the schedule task, 5 fields are specified:
I just tried to get a job to launch at 4:42PM (my approximate local time) and it worked with the following, though it took about 30 extra seconds:
If you want multiple times, I think the following should work:
for 4, 6, 8, and 10 o'clock PM every day.
在作业配置中,可以定义各种构建触发器。通过定期构建,您可以通过定义日期或星期几以及执行构建的时间来安排构建。
格式如下:
可以插入代表单词 Hash 的字母 H 来代替任何值,它将根据您的项目名称的哈希代码计算参数,这样如果您正在构建多个项目同时在构建机器上运行,假设每天午夜,它们不会同时开始构建执行,每个项目根据其哈希码在不同的分钟开始执行。您还可以指定介于数字之间的值,即 H(0,30) 将返回项目的哈希代码,其中可能的哈希值为 0-30
示例:
每天早上 08:30 开始构建,周一至周五:
工作日每天构建两次,午餐时间 12:00 和午夜 00:00,周日至周四:
每天下午 4:00 pm - 4:59 pm 或 16:00 -16:59 之间开始构建,具体取决于项目哈希:
在午夜开始构建:
或在每周六午夜开始构建:
每月第一天凌晨 2:00 - 02:30 之间:
有关 CRON 表达式的更多信息
In the job configuration one can define various build triggers. With periodically build you can schedule the build by defining the date or day of the week and the time to execute the build.
The format is as follows:
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 your project name, this is so that if you are building several projects on your build machine at the same time, lets say midnight each day, they do not all start there 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:
weekday daily build twice a day, at lunchtime 12:00 and midnight 00:00, Sunday to Thursday:
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:
start build at midnight:
or start build at midnight, every Saturday:
every first of every month between 2:00 a.m. - 02:30 a.m. :
more on CRON expressions
这个例子是每天发生的,一次是上午 9 点左右,一次是下午 5 点左右。 (根据评论编辑)。
This example is everyday, once around 9am and once around 5pm. (edited per comments).
在 Jenkins 中安排作业的步骤:
@midnight
注意:在计划字段下,可以看到最后一个和最后一个下一个日期时间运行。
@hourly
、@daily
、@weekly
、@每月
,@midnight
@hourly
-->每小时开始时构建 -->0 * * * *
@daily,@midnight
-->每天午夜构建 -->0 0 * * *
@weekly
-->每周周日早上午夜构建 -->0 0 * * 0
@monthly
-->每月第一天午夜构建 -->0 0 1 * *
The steps for schedule jobs in Jenkins:
@midnight
Note: under the schedule field, can see the last and the next date-time run.
@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 * *
要每天在下午 4 点到 6 点之间构建一次,您可以使用
H H(15-17) * * *
To build once a day between say 4PM to 6PM you can use
H H(15-17) * * *
周一至周五之间每 2 小时构建一次
MON-FRI build every 2 hour between
这似乎是一个 cron 表达式。请注意,您的示例仅在每月一号到七号的 16:00 构建。您可能有某种其他错误,或者 Jenkins 使用非标准 CRON 表达式。
That appears to be a cron expression. Note that your example builds only on the first to seventh of every month, at 16:00. You likely have some sort of other error, or Jenkins uses non-standard CRON expressions.