简体   繁体   English

关于配置jenkins在git push commits之前运行测试的教程

[英]tutorial about configuring jenkins to run tests before git pushing commits

I have a local git repository, and also have a working jenkins project. 我有一个本地git存储库,也有一个正在运行的jenkins项目。

I'd like to hook the jenkins task, so that before pushing any changes to the remote repo the jenkins project gets executed, and if the tests dont's succeed git stops the push 我想钩住jenkins任务,以便在将任何更改推送到远程仓库之前,先执行jenkins项目,如果测试失败,则git会停止推送

I thought this should be a pretty common scenario, but I've been googling around and I couldn't find a tutorial explaining 我以为这应该是一个很常见的情况,但是我一直在搜寻,却找不到教程来解释

I think the reason that you're not seeing this scenario out in the wild is that it sounds like you're trying to solve a clean code / dirty code separation by using separate repos as opposed to separate branches, which is the norm. 我认为您没有在野外看到这种情况的原因是,这听起来像是您试图通过使用单独的存储 (而不是单独的分支)来解决干净的代码/肮脏的代码分离,这是正常现象。

Perhaps instead, you have a single remote that Jenkins is listening to, and perhaps is listening to (say) the 'dev' branch. 也许相反,您有一个Jenkins正在监听的远程控制器,也许正在监听(说)“ dev”分支。 You push from your local to the remote dev branch. 您从本地推送到远程dev分支。 Jenkins listens, builds when it sees a change, and if it likes what it sees, merges that to 'master'. Jenkins会侦听并在看到更改时进行构建,如果喜欢所看到的,则将其合并为“ master”。

Then your dirty code is on the dev branch, separate from the clean code on your master branch. 然后,您的脏代码在dev分支上,与主分支上的干净代码分开。

This is a more conventional way of solving this type of problem.. you'll probably find more support for this model. 这是解决此类问题的更常规的方式。.您可能会发现对此模型的更多支持。

It is actually a pretty common scenario, but that doesn't mean that will be easy to accomplish. 这实际上是一个很常见的场景,但这并不意味着将很容易实现。

The best thing to do, as a starting point, is to read the Jenkins official documentation . 作为起点,最好的办法是阅读Jenkins官方文档

From there, you can read specific articles, like this one , that talks about one hook that does something similiar to what you want. 从那里,您可以阅读诸如此类的特定文章, 文章讨论了一个挂钩,该挂钩可以执行与您想要的类似的操作。

You could push to a repository Jenkins monitors for changes. 您可以将其推送到Jenkins监控的存储库中进行更改。 As the last build step (ie after everything else has succeeded) you could then push the changes to the actual remote repository. 作为最后的构建步骤(即,在其他所有操作成功之后),您可以将更改推送到实际的远程存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM