0

Jenkins ver. 2.150.3

I have a multi-branch pipeline set up. I am using a declarative Jenkinsfile. I have a set of jobs which take a long time to run. I want these to run over night for any branches which have changes.

In the past, one could use the 'Suppress automatic SCM triggering' option along with a cron trigger to achieve the nightly build for branches with changes. (See Run nightly jobs on multibranch pipeline with declarative Jenkinsfile

I no longer have access to the 'Suppress automatic SCM triggering' option.

Image of missing 'Suppress automatic SCM triggering' option

The following trigger will run even if there are no changes to the code in the branch.

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

The following code runs if there are changes in the branch. However, the Jenkins multibranch project seems to trigger from the push rather than the pollSCM. This doesn't seem to achieve my desired outcome of running once nightly per branch if there are changes.

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

How do I configure Jenkins to achieve the nightly jobs per branch only if changes exist in that branch?

  • Do you have a Post commit hook configured? If so, can you try to add `ignorePostCommitHooks` in your pollSCM? I'm not sure how you can access it via Declaretive pipeline, but we use it in a scripted pipeline like this: `[$class: "SCMTrigger", scmpoll_spec: "H 0 * * * *", ignorePostCommitHooks: true]` – Unforgettable631 Aug 16 '19 at 09:35
  • I'm currently using the GitHub Enterprise "Jenkins (GitHub plugin)" Service, which is also being deprecated ... yikes. I'm fully committed to the declarative pipeline at this point. – chris094568 Aug 19 '19 at 17:33
  • When I use the `pipeline-syntax` for declarative Directive Generator the syntax looks almost the same:`triggers { pollSCM ignorePostCommitHooks: true, scmpoll_spec: 'H H * * * ' }`. Can you try that? More options available at `/directive-generator/`. – Unforgettable631 Aug 19 '19 at 18:45
  • @Unforgettable631, That seemed to do the trick. Thanks for the tip on using the directive-generator. I didn't know about that tool. – chris094568 Aug 21 '19 at 19:34

1 Answers1

1

Adding answer from comment to here.

You can achieve this by using the following script:

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

With directive generator (available at <yourJenkinsUrl>/directive-generator/ you can generate scripts available in your instance + see some documentation, 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.

Unforgettable631
  • 940
  • 6
  • 10