如何在推送到掌握时使用 Git 触发 Jenkins CI? [英] How can I make Jenkins CI with Git trigger on pushes to master?

查看:12
本文介绍了如何在推送到掌握时使用 Git 触发 Jenkins CI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为使用 GitHub 的项目设置 Jenkins-ci.我已经使用适当的插件设置了 Jenkins.我希望 Jenkins 仅在项目中的某个人推动掌握时才运行构建脚本.到目前为止,我已经能够对其进行设置,以便在任何人推送到任何地方时都会触发构建,但这太宽泛了.我已经在 Git 上使用 post-receive 服务挂钩完成了这项工作.

I'm trying to set up Jenkins-ci for a project using GitHub. I've already set up Jenkins with the appropriate plugins. I want Jenkins to run build scripts only whenever someone on the project pushes to master. So far I've been able to set it up so that a build will be triggered anytime anyone pushes to anywhere, but that is too broad. I've done this with post-receive service hooks on Git.

我已经阅读了 Jenkins wiki 和一些教程,但是缺少这个特定的细节......这可能与轮询有关吗?还是应该在 Git 端完成工作,以便 Git 仅在 master 更改时触发 Jenkins?

I've read the Jenkins wiki, and a couple of tutorials, but this particular detail is missing... is it something to do with polling maybe? Or should work be done on the Git side, so that Git only triggers Jenkins when master is changed?

推荐答案

正如 gezzed 在他的评论中已经指出的,同时有一个很好的解决方案(在 轮询必须死:从一个触发 Jenkins 构建Git钩子):

As already noted by gezzed in his comment, meanwhile there is a good solution (described in Polling must die: triggering Jenkins builds from a Git hook):

  • 将 Jenkins 作业的构建触发器设置为 Poll SCM,但不要指定时间表.

创建一个 GitHub post-receive 触发器来通知 URL

Create a GitHub post-receive trigger to notify the URL

http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>?token=<get token from git to build remotely>

  • 这将触发所有轮询指定 Git 存储库的构建.

  • This will trigger all builds that poll the specified Git repository.

    然而,轮询实际上会检查是否有任何内容被推送到所使用的分支.

    However, polling actually checks whether anything has been pushed to the used branch.

    效果很好.

    这篇关于如何在推送到掌握时使用 Git 触发 Jenkins CI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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