运行 使用声明性 Jenkinsfile 的多分支管道上的夜间作业,没有弃用的功能 'Suppress automatic SCM triggering'

Run nightly jobs on multibranch pipeline with declarative Jenkinsfile without deprecated feature 'Suppress automatic SCM triggering'

詹金斯版本。 2.150.3

我设置了多分支管道。我正在使用声明性 Jenkinsfile。我有一组作业需要很长时间才能完成 运行。对于任何有变化的分支,我希望这些 运行 过夜。

过去,可以使用 'Suppress automatic SCM triggering' 选项和 cron 触发器来实现对有更改的分支的夜间构建。 (参见 Run nightly jobs on multibranch pipeline with declarative Jenkinsfile

我无法再使用 'Suppress automatic SCM triggering' 选项。

即使分支中的代码没有更改,以下触发器也会 运行。

triggers {
    cron('H 0 * * * *')
}

下面的代码运行s如果分支有变化。但是,Jenkins 多分支项目似乎是从推送而不是 pollSCM 触发的。如果有变化,这似乎没有达到我 运行 每个分支每晚 ning 一次的预期结果。

triggers {
    pollSCM('H 0 * * * *')
}

如何配置 Jenkins 以仅在该分支中存在更改时才实现每个分支的夜间作业?

正在将评论中的答案添加到此处。

您可以使用以下脚本实现此目的:

triggers {
  pollSCM ignorePostCommitHooks: true, scmpoll_spec: 'H H * * *'
}

使用指令生成器(可在 <yourJenkinsUrl>/directive-generator/ 获得,您可以生成实例中可用的脚本 + 查看一些文档,f.e。:

To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For 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.