返回「计算机、信息技术与工程」

【Jenkins】Jenkins cron syntax

更多
Markdown 结构化数据
本文目录 9 个章节

【Jenkins】Jenkins cron syntax

# 【Jenkins】Jenkins cron syntax

创建时间:2021/6/20 20:01

  • Jenkins cron syntax
    • Introduction of cron
    • 用法
      • Hash
      • */3与H/3
      • 关于DOM与DOW的冲突
      • Nonstandard predefined scheduling definitions
    • 例子
    • Ref

Jenkins cron syntax

Introduction of cron

The software utility cron also known as cron job is a time-based job scheduler in Unix-like computer operating systems. Users who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals.

用法

Each line consists of 5 fields separated by TAB or whitespace:

Each of these fields can be either an asterisk (meaning all valid values), an element , or a list of elements separated by commas.

string a = "test";
string tmp = "est";
string b = "t" + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));
  • * specifies all valid values
  • M-N specifies a range of values
  • M-N/X or */X steps by intervals of X through the specified range or whole valid range
  • A,B,…,Z enumerates multiple values

Hash

目的: To produce even load on the system 使用随机的执行时间,保持系统的负载均衡。例如:避免每天执行的任务,都在每天0点0分执行。

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.

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.

*/3与H/3

Beware that for the day of month field, short cycles such as */3 or H/3 will not work consistently near the end of most months, due to variable month lengths. For example, */3 will run on the 1st, 4th, …31st days of a long month, then again the next day of the next month. Hashes are always chosen in the 1-28 range, so H/3 will produce a gap between runs of between 3 and 6 days at the end of a month. (Longer cycles will also have inconsistent lengths but the effect may be relatively less noticeable.)

关于DOM与DOW的冲突

If either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched.

Nonstandard predefined scheduling definitions

assets/0024 - 【Jenkins】Jenkins cron syntax__resource-001-657186b03182.png

Jenkins中的情况不太一样: @yearly, @annually, @monthly, @weekly, @daily, @midnight, and @hourly These use the hash system for automatic balancing. For example, @hourly is the same as H * * * * and could mean at any time during the hour. @midnight actually means some time between 12:00 AM and 2:59 AM.

例子

  1. Runs at 23:45 (11:45 PM) every Saturday.
string a = "test";
string tmp = "est";
string b = "t" + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));
  1. every ten minutes in the first half of every hour
string a = "test";
string tmp = "est";
string b = "t" + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));
  1. once every two hours at 45 minutes past the hour starting at 9:45 AM and finishing at 3:45 PM every weekday.
string a = "test";
string tmp = "est";
string b = "t" + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));
  1. once in every two hours slot between 9 AM and 5 PM every weekday (perhaps at 10:38 AM, 12:38 PM, 2:38 PM, 4:38 PM)
string a = "test";
string tmp = "est";
string b = "t" + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

assets/0024 - 【Jenkins】Jenkins cron syntax__resource-002-57a0ece739ef.png

图片来源:https://www.jenkins.io/doc/book/pipeline/syntax/

Ref

https://en.wikipedia.org/wiki/Cron https://www.jenkins.io/doc/book/pipeline/syntax/ https://pubs.opengroup.org/onlinepubs/007904975/utilities/crontab.html