如何在 Jenkins 中安排构建?

发布于 2024-11-28 20:46:30 字数 175 浏览 3 评论 0原文

如何安排 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

表情可笑 2024-12-05 20:46:31

在 Jenkins 中,我们的格式如下:

分钟(0-59) 小时(0-23) 日(1-7) 月(1-12) 星期

In Jenkins , we have the format is as:

Minute(0-59) Hour(0-23) Day(1-7) Month(1-12) Day of the Week

寻找一个思念的角度 2024-12-05 20:46:31

Jenkins 使用 Cron 表达式

您只需输入@hourly即可安排每小时构建。

Jenkins uses Cron Expressions.

You can simply schedule hourly builds by just typing@hourly.

讽刺将军 2024-12-05 20:46:31

周一至周日下午 4 点试试这个

0 16 * * *

您可以在 Jenkins 下的“定期构建”中查看配置时显示的描述消息。(请参阅下面给出的屏幕截图)

“最后一次运行时间为 2019 年 11 月 17 日星期日下午 4:00:05 IST;
下次运行时间为 2019 年 11 月 18 日星期一下午 4:00:05(美国标准时间)。”

屏幕截图

在此处输入图像描述

“2019 年 11 月 18 日星期一 4:00:05 PM IST”时间中的指的是我们的当前系统秒数。

Try this for 4 PM from Monday to Sunday

0 16 * * *

You can check the description messgage displayed while you configuring in "Build periodically' under Jenkins. (Refer the screenshot given below)

"Would last have run at Sunday, November 17, 2019 4:00:05 PM IST;
would next run at Monday, November 18, 2019 4:00:05 PM IST."

Screenshot

enter image description here

The seconds in the time " Monday, November 18, 2019 4:00:05 PM IST" refers to our current system seconds.

晒暮凉 2024-12-05 20:46:30

更新: 请阅读其他答案和评论,因为它们包含我第一次回答这个问题时所不知道的更多信息(例如哈希函数)。

根据 Jenkins 的说法计划任务的自己的帮助(“?”按钮),指定了 5 个字段:

该字段遵循 cron 的语法(有细微差别)。具体来说,每行由 5 个由 TAB 或空格分隔的字段组成:
分钟小时 DOM 月指数

我只是试图在下午 4:42(我的大约当地时间)启动一份工作,它与以下内容一起工作,尽管多花了大约 30 秒:

42 16 * * *

如果您想要多次,我认为以下应该工作时间:

0 16,18,20,22 * * *

每天下午 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:

This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:
MINUTE HOUR DOM MONTH DOW

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:

42 16 * * *

If you want multiple times, I think the following should work:

0 16,18,20,22 * * *

for 4, 6, 8, and 10 o'clock PM every day.

未央 2024-12-05 20:46:30

在作业配置中,可以定义各种构建触发器。通过定期构建,您可以通过定义日期或星期几以及执行构建的时间来安排构建。

格式如下:

分钟 (0-59)、小时 (0-23)、日 (1-31)、月 (1-12)、星期几
(0-6)

可以插入代表单词 Hash 的字母 H 来代替任何值,它将根据您的项目名称的哈希代码计算参数,这样如果您正在构建多个项目同时在构建机器上运行,假设每天午夜,它们不会同时开始构建执行,每个项目根据其哈希码在不同的分钟开始执行。您还可以指定介于数字之间的值,即 H(0,30) 将返回项目的哈希代码,其中可能的哈希值为 0-30

示例:

每天早上 08:30 开始构建,周一至周五:

  • 30 08 * * 1-5

工作日每天构建两次,午餐时间 12:00 和午夜 00:00,周日至周四:

  • 00 0,12 * * 0-4

每天下午 4:00 pm - 4:59 pm 或 16:00 -16:59 之间开始构建,具体取决于项目哈希:

  • H 16 * * 1-5

在午夜开始构建:

  • @midnight

或在每周六午夜开始构建:

  • 59 23 * * 6

每月第一天凌晨 2:00 - 02:30 之间:

  • H(0-30) 02 01 * *

有关 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:

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 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:

  • 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 * *

more on CRON expressions

鹿童谣 2024-12-05 20:46:30

这个例子是每天发生的,一次是上午 9 点左右,一次是下午 5 点左右。 (根据评论编辑)。

H 9,17 * * * 

This example is everyday, once around 9am and once around 5pm. (edited per comments).

H 9,17 * * * 
无需解释 2024-12-05 20:46:30

在 Jenkins 中安排作业的步骤:

  1. 单击作业要求的“配置”
  2. ,向下滚动到“构建触发器” - 副标题
  3. 单击定期构建复选框
  4. 在 Schedule 字段中添加时间表,例如 @midnight

在此处输入图像描述

注意:在计划字段下,可以看到最后一个和最后一个下一个日期时间运行。

Jenkins 还支持预定义别名来安排构建:

@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:

  1. click on "Configure" of the job requirement
  2. scroll down to "Build Triggers" - subtitle
  3. Click on the checkBox of Build periodically
  4. Add time schedule in the Schedule field, for example, @midnight

enter image description here

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 * *

温柔女人霸气范 2024-12-05 20:46:30

要每天在下午 4 点到 6 点之间构建一次,您可以使用

H H(15-17) * * *

To build once a day between say 4PM to 6PM you can use

H H(15-17) * * *

苍风燃霜 2024-12-05 20:46:30
H H(5-21)/2 * * 1-5

周一至周五之间每 2 小时构建一次

H H(5-21)/2 * * 1-5

MON-FRI build every 2 hour between

护你周全 2024-12-05 20:46:30

这似乎是一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文