如何阻止 Jenkins 作业在特定时间运行

问题描述 投票:0回答:3

我有一项 Jenkins 工作,它会重启我们的小型内部生产系统。它是完全自动化的,因此当我们签入代码更改时,我们会运行测试和其他验证步骤,最后自动部署新版本。

重新启动系统通常不是问题,因为它很快就会恢复,而且人们知道时不时可能会出现小规模中断。

然而,白天有时我知道系统被大量使用,因此想阻止任何自动重启。

有没有办法做到这一点,例如配置作业根本不运行的时间范围? IE。类似于“工作日 8 点到 10 点”或任何其他基于 cron 的时间表。

我能想到的唯一选择是通过一些 cli 命令定期禁用和启用作业,但希望有更好的方法来做到这一点。

jenkins jenkins-plugins
3个回答
4
投票

您可以使用 Conditional BuildStep 插件并设置一些可以启动(或不启动)作业的时间范围。

类似的东西:

enter image description here


0
投票

你也可以使用

Jenkins
插件https://plugins.jenkins.io/datetime-constraint/
它可以帮助您设置抛出 UI 的时间范围。你可以做如下

周一 10 点之前,8 点之后
周二 10 点之前,8 点之后
等等

管道将在这些时间自动中止。


0
投票

你也可以使用

Jenkins
working-hours插件由@Jeff Pearce维护

The working hours plugin allows you to set up a schedule of allowable build times; projects can opt in to use the schedule to prevent them from running outside of configured allowable build times. If a build is scheduled during non-working hours then it is kept in the build queue until the next allowable time.

Jobs opt in via the enforceBuildSchedule job parameter, which is provided by this plugin. It can optionally take in a branches parameter to limit it's usage to only those branches. This only works in MultiBranchPipelines.

用法:

 Sample job (scripted pipeline):
 
 node {   
   properties([enforceBuildSchedule()])   
   stage('Do some stuff')
   {
      echo 'this can wait til morning'   
   } 
 }
© www.soinside.com 2019 - 2024. All rights reserved.