Can I restrict poll SCM job to be run only once in a day?

北战南征 提交于 2019-12-25 06:49:58

问题


I have a poll SCM job , which polls every 5 minutes for a change in Perforce. But I need the job to be triggered only when first edit happens for the files in perforce in a day. Can I restrict poll SCM job to be run only once in a day?


回答1:


Jenkins itself does not provide this kind of behaviour ("run only for the very first change every day").

You need to split this down into two parts; the first one polling SCM, the second taking care that the job will not run more than once per day.

Possible solution:

  • Keep your current polling job, checking for changes every 5 minutes
  • add a build step that will disable the job after running (thus preventing a second run on this day)
  • create another job that (re-)enables the polling job every morning at 0:00, so the polling job can run upon the next change

If you don't like to see the polling job going into "disabled" state, then you could also remove the job's SCM polling from the job configuration at the end of the run, and have the second job re-establish that. This is a bit more complicated as you need to modify the job configuration.

In any case, "change" will always refer to the last run of the polling job. So if there's two changes A and B on day 1, then the polling job will run once for "A" on day 1, and then immediately again for "B" on day 2.




回答2:


You need to mark Poll SCM instead of Build Periodically.

In Poll SCM you can write a cron-like entry how often your polling should run, e.g. for once a day (run at 1:00am):

0 1 * * *


来源:https://stackoverflow.com/questions/37827102/can-i-restrict-poll-scm-job-to-be-run-only-once-in-a-day

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