小智 27
您可以使用以下语法设置作业参数:
properties([pipelineTriggers([cron('H 23 * * *')])])
Run Code Online (Sandbox Code Playgroud)
将此行添加到构建脚本或Jenkinsfile将配置作业每晚11点运行.
Bar*_*oży 26
声明性管道有triggers指令,一个像这样使用它:
triggers { cron('H 4/* 0 0 1-5') }
Run Code Online (Sandbox Code Playgroud)
完整示例(摘自文档)参考:https : //jenkins.io/doc/book/pipeline/syntax/#triggers
pipeline {
agent any
triggers {
cron('H */4 * * 1-5')
}
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
进入管道的主要作业配置(第一个),设置"定期构建"复选框,并指定所需的计划.
按照语法指示.
Run Code Online (Sandbox Code Playgroud)the 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 MINUTE Minutes within the hour (0–59) HOUR The hour of the day (0–23) DOM The day of the month (1–31) MONTH The month (1–12) DOW The day of the week (0–7) where 0 and 7 are Sunday. To specify multiple values for one field, the following operators are available. In the order of precedence, * 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 Examples: # every fifteen minutes (perhaps at :07, :22, :37, :52) H/15 * * * * # every ten minutes in the first half of every hour (three times, perhaps at :04, :14, :24) H(0-29)/10 * * * * # once every two hours every weekday (perhaps at 9:38 AM, 11:38 AM, 1:38 PM, 3:38 PM) H 9-16/2 * * 1-5 # once a day on the 1st and 15th of every month except December H H 1,15 1-11 *
小智 6
如果您想使用多分支管道定期为特定分支运行作业,您可以在 Jenkinsfile 中执行此操作:
def call(String cronBranch = 'master') {
// Cron job to be run from Monday to Friday at 10.00h (UTC)
String cronString = BRANCH_NAME == cronBranch ? "0 10 * * 1-5" : ""
pipeline {
agent any
triggers {
cron(cronString)
}
stages {
stage('My Stage') {
//Do something
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您需要第一次手动运行此作业才能添加。
| 归档时间: |
|
| 查看次数: |
40826 次 |
| 最近记录: |