Github Webhooks-预推钩 [英] Github webhooks - pre-push hooks

查看:80
本文介绍了Github Webhooks-预推钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是,每当开发人员推送至github时,则在推送之前,CI构建都应在Jenkins服务器上触发.如果该构建失败,则应拒绝推送到github. 我需要为此编写钩子,但是我不想编写客户端钩子,因为开发人员可以禁用它们.我想要服务器端github webhooks或预接收钩子.

My requirement is that whenever developers are pushing to github, then before the push a CI build should trigger on Jenkins server. If that build fails, then push to github should be rejected. I need to write hooks for this, but I don't want to write client-side hooks as they can be disabled by developers. I want server-side github webhooks or pre-receive hooks.

现在,这是否有可能实现? 如果是,那么从哪里开始呢?我需要Rest API的知识吗?我需要编写shell脚本吗?

Now, is this even possible to achieve ? If yes, then where to begin? Do I need knowledge of Rest API? Do I need to write shell scripts?

推荐答案

通常这不是GitHub上可能的工作流程.
您宁愿使用带有2个GitHub存储库的受保护的提交"模型:

This isn't generally the workflow possible with GitHub.
You would rather use a "guarded commits" model with 2 GitHub repo:

  • one for pushing, where you can enable a CI service like, for instance, Travis (or your own CI server),
  • one for valid commits (the ones that passed CI), pushed by Travis (as in this question), and used by developer to sync their repo (pull only, no push)

这就是我的项目的要求,不能更改

that's what the requirement is for my project, which can't be changed

在这种情况下,最好遵循构建CI服务器,它将:

In that case, It is best to follow Building a CI server which will:

  • 检测推送并触发编译
  • 在专用分支上重新进行有效的通信(例如,可以是master分支)

这意味着开发人员只应将其推送到由您的服务器监视的"dev"分支,并且如果编译通过,则CI引擎会将这些提交推送到master分支.

That means the devs should push only to a "dev" branch, monitored by your server, and your CI engine would push those commits to the master branch if the compilation passes.

这篇关于Github Webhooks-预推钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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