使用声明性Jenkinsfile在多分支管道上运行每晚作业 [英] Run nightly jobs on multibranch pipeline with declarative Jenkinsfile

查看:233
本文介绍了使用声明性Jenkinsfile在多分支管道上运行每晚作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins版本2.121.2

Jenkins version 2.121.2

我建立了多分支管道.我正在使用声明性的Jenkinsfile.

I have a multi-branch pipeline set up. I am using a declarative Jenkinsfile.

我有一组测试,这些测试需要很长时间才能运行.我希望这些通宵查询所有有变化的分支.

I have a set of tests which take a long time to run. I want these to run over night for any branches which have changes.

我尝试了一些尝试,但当前失败的尝试是:

I have tried a few things but my current failing attempt is:

  • 在任务下>配置,我启用了抑制自动SCM触发"

  • Under the job > configure, I have enabled 'Suppress automatic SCM triggering'

将扫描多分支管道触发器">如果没有运行则定期运行"设置为1分钟(仅出于测试目的,我会在工作时增加此值)

Have 'Scan Multibranch Pipeline Triggers' > 'Periodically if not otherwise run' set to 1 minute (just for testing, I will increase this when it is working)

在我的Jenkinsfile中(凌晨4点运行的示例),我还尝试了pollSCM():

In my Jenkinsfile (example for a 4am run), I have also tried with pollSCM():

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

在扫描多分支管道日志"中,我看到以下内容,但没有工作在凌晨4点运行(时间在我的Jenkinsfile中的trigger()中):

In the 'Scan multibranch pipeline log' I see the following but no job runs at 4am (time in the trigger() in my Jenkinsfile):

Changes detected: my-feature-branch (1234567890abcdefgh → abcdefgh123456789)
Did not schedule build for branch: my-feature-branch

我在做什么错了?

因此,我尝试了此设置:

So I've tried this set up instead:

将cron设置为每15分钟一次

Set the cron to every 15 minutes

triggers {
  cron('5,20,35,50 * * * *')
}

删除了禁止自动SCM触发"用户界面中配置"下的设置

Removed the setting under configure in the UI 'Suppress automatic SCM triggering'

但是它只是在发生分钟轮询(此测试中每小时凌晨16分钟)后才开始运行.

But it just starts running the minute polling has happened (16 minutes past the hour in this test).

我什么都不做似乎要注意我的cron设置?

What ever I do nothing seems to pay attention to my cron settings?

如果我进入UI的分支作业下的查看配置",它会显示来自我的Jenkinsfile的UI设置.

If I got to 'View configuration' under the branch job in the UI it shows the UI settings from my Jenkinsfile ok.

再次编辑!:

因此,在最后一次编辑中,它实际上确实立即运行,然后在cron时间再次运行.

So with the last edit, it did actually run immediately and then again at the cron time.

现在,在用户界面中再次启用了禁止自动SCM触发"设置.

Now enabled again in the UI the setting 'Suppress automatic SCM triggering'.

我可以正常工作了!我意识到的主要问题(a)更改未应用我不认为Jenkinsfile中的更改在第一次运行后才运行? (b)我还安装了下一个执行插件,以便可以更好地了解它的计划.

And I have it working! The main issue I realised (a) changes are not applied I do not think until the run after the first run with a change in the Jenkinsfile? (b) Also I installed the next execution plugin so I can see what it is planning on better.

推荐答案

此处的问题是在multibranchPipelineJob中声明的触发器用于扫描多分支.要运行作业,定期在管道中声明触发器,如下所示:

The issue here was that trigger declared in multibranchPipelineJob is for scanning multibranch. To run job periodically declare trigger in pipeline like this:

pipeline {
    triggers {
        cron('45 6 * * 1-5')
    }
    agent {
    ...

这篇关于使用声明性Jenkinsfile在多分支管道上运行每晚作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆