{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/jenkins-cron-syntax/",
  "atlas": "https://www.pystone.net/?node=jenkins-cron-syntax#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/jenkins-cron-syntax.md",
  "context": "https://www.pystone.net/notes/jenkins-cron-syntax.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:jenkins-cron-syntax",
  "slug": "jenkins-cron-syntax",
  "title": "【Jenkins】Jenkins cron syntax",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "【Jenkins】Jenkins cron syntax",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "d7bb6b6d3d83178f497bcaa8c63332ef553ac886cc3ddd57df9c7fb2fb052446",
  "assets": [
    {
      "reference": "assets/0024 - 【Jenkins】Jenkins cron syntax__resource-001-657186b03182.png",
      "url": "/media/393090d13c743af5f507.png",
      "mediaType": "image/png",
      "contentHash": "393090d13c743af5f50777adb5154595c6156e44f9fe05bea28f1fbb95890501",
      "byteLength": 16438,
      "width": 686,
      "height": 219
    },
    {
      "reference": "assets/0024 - 【Jenkins】Jenkins cron syntax__resource-002-57a0ece739ef.png",
      "url": "/media/a25de05a0c8ed7171fce.png",
      "mediaType": "image/png",
      "contentHash": "a25de05a0c8ed7171fcef2536fb7fe8b923d6b2b8fcb72e8a1a9d1d631e4af21",
      "byteLength": 27006,
      "width": 907,
      "height": 666
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "【Jenkins】Jenkins cron syntax",
      "anchor": "jenkinsjenkins-cron-syntax",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#jenkinsjenkins-cron-syntax"
    },
    {
      "depth": 2,
      "text": "Jenkins cron syntax",
      "anchor": "jenkins-cron-syntax",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#jenkins-cron-syntax"
    },
    {
      "depth": 3,
      "text": "Introduction of cron",
      "anchor": "introduction-of-cron",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#introduction-of-cron"
    },
    {
      "depth": 3,
      "text": "用法",
      "anchor": "用法",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#%E7%94%A8%E6%B3%95"
    },
    {
      "depth": 4,
      "text": "Hash",
      "anchor": "hash",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#hash"
    },
    {
      "depth": 4,
      "text": "/3与H/3",
      "anchor": "3与h3",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#3%E4%B8%8Eh3"
    },
    {
      "depth": 4,
      "text": "关于DOM与DOW的冲突",
      "anchor": "关于dom与dow的冲突",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#%E5%85%B3%E4%BA%8Edom%E4%B8%8Edow%E7%9A%84%E5%86%B2%E7%AA%81"
    },
    {
      "depth": 4,
      "text": "Nonstandard predefined scheduling definitions",
      "anchor": "nonstandard-predefined-scheduling-definitions",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#nonstandard-predefined-scheduling-definitions"
    },
    {
      "depth": 3,
      "text": "例子",
      "anchor": "例子",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#%E4%BE%8B%E5%AD%90"
    },
    {
      "depth": 2,
      "text": "Ref",
      "anchor": "ref",
      "citation": "https://www.pystone.net/notes/jenkins-cron-syntax/#ref"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:software-engineering-and-quality",
      "title": "软件工程与质量保障",
      "url": "https://www.pystone.net/notes/software-engineering-and-quality/",
      "atlas": "https://www.pystone.net/?node=software-engineering-and-quality#knowledge-atlas",
      "label": "软件工程与质量保障",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "CI-CD与质量保障/CI-CD工具链中的“【Jenkins】Jenkins cron syntax”导航项",
      "citation": "https://www.pystone.net/notes/software-engineering-and-quality/#ci-cd%E4%B8%8E%E8%B4%A8%E9%87%8F%E4%BF%9D%E9%9A%9Cci-cd%E5%B7%A5%E5%85%B7%E9%93%BE"
    }
  ],
  "contentMarkdown": "# 【Jenkins】Jenkins cron syntax\n\n﻿# 【Jenkins】Jenkins cron syntax\n\n> 创建时间：2021/6/20 20:01\n\n* Jenkins cron syntax\n    * Introduction of cron\n    * 用法\n      * Hash\n      * */3与H/3\n      * 关于DOM与DOW的冲突\n      * Nonstandard predefined scheduling definitions\n    * 例子\n  * Ref\n\n## Jenkins cron syntax\n\n### Introduction of cron\n\nThe 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.\n\n### 用法\n\nEach line consists of 5 fields separated by TAB or whitespace:\n\nEach of these fields can be either an **asterisk** (meaning all valid values), **an element** , or **a list of elements separated by commas**.\n\n```csharp\nstring a = &quot;test&quot;;\nstring tmp = &quot;est&quot;;\nstring b = &quot;t&quot; + tmp;\nConsole.WriteLine(string .ReferenceEquals(str1, str2));\n\n```\n\n  * `*` specifies all valid values\n  * M-N specifies a range of values\n  * `M-N/X` or `*/X` steps by intervals of X through the specified range or whole valid range\n  * `A,B,…,Z` enumerates multiple values\n\n#### Hash\n\n目的： **To produce even load on the system**\n使用随机的执行时间，保持系统的负载均衡。例如：避免每天执行的任务，都在每天0点0分执行。\n\nFor 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.\n\n> 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.\n\n#### */3与H/3\n\nBeware 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.)\n\n#### 关于DOM与DOW的冲突\n\nIf 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.\n\n#### Nonstandard predefined scheduling definitions\n\n![](assets/0024 - 【Jenkins】Jenkins cron syntax__resource-001-657186b03182.png)\n\n> Jenkins中的情况不太一样：\n>  `@yearly`, `@annually`, `@monthly`, `@weekly`, `@daily`, `@midnight`, and `@hourly`\n>  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.\n\n### 例子\n\n  1. Runs at 23:45 (11:45 PM) every Saturday.\n\n```csharp\nstring a = &quot;test&quot;;\nstring tmp = &quot;est&quot;;\nstring b = &quot;t&quot; + tmp;\nConsole.WriteLine(string .ReferenceEquals(str1, str2));\n\n```\n  2. every ten minutes in the first half of every hour\n\n```csharp\nstring a = &quot;test&quot;;\nstring tmp = &quot;est&quot;;\nstring b = &quot;t&quot; + tmp;\nConsole.WriteLine(string .ReferenceEquals(str1, str2));\n\n```\n  3. once every two hours at 45 minutes past the hour starting at 9:45 AM and finishing at 3:45 PM every weekday.\n\n```csharp\nstring a = &quot;test&quot;;\nstring tmp = &quot;est&quot;;\nstring b = &quot;t&quot; + tmp;\nConsole.WriteLine(string .ReferenceEquals(str1, str2));\n\n```\n  4. 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)\n\n```csharp\nstring a = &quot;test&quot;;\nstring tmp = &quot;est&quot;;\nstring b = &quot;t&quot; + tmp;\nConsole.WriteLine(string .ReferenceEquals(str1, str2));\n\n```\n\n![](assets/0024 - 【Jenkins】Jenkins cron syntax__resource-002-57a0ece739ef.png)\n\n图片来源：https://www.jenkins.io/doc/book/pipeline/syntax/\n\n## Ref\n\nhttps://en.wikipedia.org/wiki/Cron\nhttps://www.jenkins.io/doc/book/pipeline/syntax/\nhttps://pubs.opengroup.org/onlinepubs/007904975/utilities/crontab.html\n"
}
