使用Jenkins Rest API安排Jenkins作业 [英] Schedule Jenkins job using Jenkins Rest API
问题描述
我有一份Jenkins工作,计划在特定时间进行.我想以编程方式修改该时间.
I have a Jenkins job which is scheduled for a specific time. I want to modify that timing programmatically.
我试图通过安装Schedule Build插件来修改构建,并使用http://jenkins_url/job/jobname/build?delay=3344sec
对其进行修改.但这会将作业置于拥有Java线程的安静时期.我希望修改Schedule条目,而不要使其处于安静状态.
I tried to modify the build by installing Schedule Build plugin and modify it using http://jenkins_url/job/jobname/build?delay=3344sec
. But this will put the job in quiet period which holds the java thread. I'm looking to modify the Schedule entry without putting it to quiet period.
推荐答案
您可以使用Build Triggers -> Build periodically
作业配置选项.使用它来指定开始新构建的确切时间.
You can use the Build Triggers -> Build periodically
job configuration option. Use that to specify the exact time for starting a new build.
如果您需要更改时间,请使用Jenkins REST API来...
If you need to change that time, use the Jenkins REST API to...
- 以编程方式检索XML格式的作业配置,然后
- 修改该配置中的计划时间(请参见下文)
- 重新发布新作业配置
在bash中,可以使用单行代码(使用curl
和sed
)来修改下面的XML部分(示例将运行时间安排为2月29日中午):
In bash, this can be done with a one-liner (using curl
and sed
) to modify the XML section below (the example schedules a run for noon, Feb 29):
[...]
<triggers>
<hudson.triggers.TimerTrigger>
<spec>00 12 29 02 * </spec>
</hudson.triggers.TimerTrigger>
</triggers>
[...]
注意:
- 此外,您无需依赖任何辅助插件
- caveat:您不能在进度表中指定年份-因此,如果您需要提前一年以上计划生成时间,那么您首先需要一些魔术.
这篇关于使用Jenkins Rest API安排Jenkins作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!