2015-08-15 134 views
9

构建管道如何安排在夜间的某个特定时间执行,就像正常工作一样?Jenkins构建管道调度触发器

+1

待办事项你的意思是来自构建管道插件的管道?如果是的话,它只是一个视图,只是添加一个“定期生成”到您的管道中的第一份工作。猜猜第一份工作是否在“Poll SCM”上运行? – mszalbach

回答

-3

如果使用Build pipeline plugin你可以简单地触发添加到第一个工作,这将触发全面管线

如果您正在使用詹金斯2.0和创造型管道的一个新项目,那么你可以简单地安排它就像你的任何其他工作

3

进入你的管道的主要工作配置(第一个),设置“定期生成”复选框,并指定你想要的时间表。

遵循语法指示。

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

如果使用多分支管道,你会如何为特定的分支做这些? –

11

您可以使用以下语法设置作业参数:

properties([pipelineTriggers([cron('H 23 * * *')])]) 

加入这行来构建脚本或Jenkinsfile将配置作业在晚上11点运行每一个夜晚。

+0

它在jenkins 2.79(java.lang.UnsupportedOperationException:未定义符号'pipelineTriggers')中的脚本管道中不起作用 – Eric

3

声明管道具有triggers指令,一个使用它是这样的:

triggers { cron('H 4/* 0 0 1-5') } 

我把它从Pipeline Syntax docs

+1

FYI:这将构建在其“Jenkinsfile”中包含此行的每个分支;也就是说,如果您在'master'或'develop'分支以及所有正在进行的功能分支中都有此功能,则它们都将按照此计划进行触发。 – dwj

+0

@dwj哪个在大多数情况下不是你想要的! – ferdy