我如何在 Jenkins 中安排工作? [英] How do I schedule jobs in Jenkins?

查看:26
本文介绍了我如何在 Jenkins 中安排工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

15 13 * * *

但它没有在预定的时间运行.

But it does not run at the scheduled time.

安排工作的程序是否正确?

Is it the correct procedure to schedule a job?

作业应该在凌晨 4:20 运行,但它没有运行.

The job should run at 4:20 AM, but it is not running.

推荐答案

通过将计划周期设置为 15 13 * * * 你告诉 Jenkins 在每年的每个月的每一天安排构建在一天的第 13 个小时的第 15 分钟.

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 使用了一个 cron 表达式,不同的字段是:

Jenkins used a cron expression, and the different fields are:

  1. MINUTES 一小时内的分钟数 (0-59)
  2. HOURS 一天中的小时数 (0-23)
  3. DAYMONTH 一个月中的第几天 (1-31)
  4. MONTH 一年中的一个月 (1-12)
  5. DAYWEEK 星期几 (0-7),其中 0 和 7 是星期日

如果你想每 5 分钟安排一次构建,这样做可以:*/5 * * * *

If you want to schedule your build every 5 minutes, this will do the job : */5 * * * *

如果你想在每天 8 点安排你的构建,这将完成这项工作:0 8 * * *

If you want to schedule your build every day at 8h00, this will do the job : 0 8 * * *

对于过去的几个版本(2014),Jenkins 有一个新参数,H(摘自 Jenkins 代码文档):

For the past few versions (2014), Jenkins have a new parameter, H (extract from the Jenkins code documentation):

为了允许定期调度的任务在系统上产生均匀的负载,应尽可能使用符号 H(代表hash").

To allow periodically scheduled tasks to produce even load on the system, the symbol H (for "hash") should be used wherever possible.

例如,将 0 0 * * * 用于十几个日常工作将导致午夜时分出现大幅峰值.相比之下,使用 H H * * * 仍然会每天执行一次每个作业,但不是同时执行所有作业,最好使用有限的资源.

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.

还要注意:

H 符号可以被认为是一个范围内的随机值,但它实际上是作业名称的散列,而不是随机函数,因此该值对于任何给定的值都保持稳定项目.

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.

更多使用H"的示例

这篇关于我如何在 Jenkins 中安排工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆