Run nightly jobs on multibranch pipeline with declarative Jenkinsfile

落花浮王杯 提交于 2019-12-10 21:03:49

问题


Jenkins version 2.121.2

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:

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

  • 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)

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

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

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

What am I doing wrong please?


Edit:

So I've tried this set up instead:

Set the cron to every 15 minutes

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

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

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

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

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


Edit (again!):

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

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

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.


回答1:


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 {
    ...


来源:https://stackoverflow.com/questions/51769750/run-nightly-jobs-on-multibranch-pipeline-with-declarative-jenkinsfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!