每 2 小时触发一次 Jenkins 构建,但前提是有 git 提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24661301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trigger Jenkins build every 2 hours but only if there was a git commit
提问by Sergey
Here is the problem that I am having - I need to trigger a job build every 2 hours but only if there was a git commit(skip if there was no activity). I can solve them individually but not sure how to solve them together - anybody has any good ideas? The only one I can come up with is a cron job that would check every 2 hours and if there is a git commit during that time, trigger a job manually, but that does not look all that elegant.
这是我遇到的问题 - 我需要每 2 小时触发一次作业构建,但前提是有 git commit(如果没有活动则跳过)。我可以单独解决它们,但不确定如何一起解决它们-有人有什么好主意吗?我唯一能想到的是一个 cron 作业,它会每 2 小时检查一次,如果在此期间有 git 提交,则手动触发作业,但这看起来并不那么优雅。
Any good ideas appreciated.
任何好的想法表示赞赏。
回答by Angelo Genovese
Set jenkins up to use the "Poll SCM" trigger every 2 hours (0 */2 * * *) or something like that
将 jenkins 设置为每 2 小时使用一次“Poll SCM”触发器(0 */2 * * *)或类似的东西
It'll update from git and, if there was a change, trigger a build.
它将从 git 更新,如果有更改,则触发构建。
回答by abhinav
H H/2 * * *
高/2 * * *
Poll SCM will occur at random minute every random intervals of 2 hrs.
轮询 SCM 将每隔 2 小时的随机时间间隔随机发生一次。
回答by Venkata Buddhiraju
If you just set Poll Scm with cron expression H H/2 * * *, it will trigger the build for every 2 hours but the build will also be triggered if a git commit happens and it is not 2 hours yet.
如果您只是使用 cron 表达式 HH/2 * * * 设置 Poll Scm,它将每 2 小时触发一次构建,但如果 git 提交发生并且还不到 2 小时,也会触发构建。
If you check option "Ignore post-commit hooks"along with the above cron expression in Poll SCM, this will Ignore changes notified by SCM post-commit hooks and now the build will be triggered only if there is a commit and it has been 2 hours.
如果您在Poll SCM 中选中选项“忽略提交后钩子”以及上述 cron 表达式,这将忽略由 SCM 提交后钩子通知的更改,现在只有在提交且为 2 时才会触发构建小时。
With this step you can completely avoid any manual intervention to trigger builds.
通过此步骤,您可以完全避免任何手动干预来触发构建。
The help icon for this option explains its feature clearly as,
此选项的帮助图标清楚地说明了其功能,
This can be useful if you want to prevent some long-running jobs (e.g. reports) starting because of every commit, but still want to run them periodic if SCM changes have occurred.
Note that this option needs to be supported by the SCM plugin, too! The subversion-plugin supports this since version 1.44.
如果您想防止某些长时间运行的作业(例如报告)因每次提交而启动,但仍希望在发生 SCM 更改时定期运行它们,这会很有用。
请注意,此选项也需要 SCM 插件支持!subversion-plugin 从 1.44 版开始支持这个。
I have GIT 2.4.0 and is working fine with this option.
我有 GIT 2.4.0 并且使用此选项工作正常。
回答by gareth_bowles
Just set up the job to poll SCM every 2 hours. If there was a commit in the previous 2 hours it will build.
只需将作业设置为每 2 小时轮询一次 SCM。如果在前 2 小时内有提交,它将构建。