Jenkins:如何从git存储库构建多个顶级项目? [英] Jenkins: How To Build multiple top-level projects from a git repository?

查看:220
本文介绍了Jenkins:如何从git存储库构建多个顶级项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一堆顶级maven项目的Git仓库(每个仓库都有自己的子目录和一个pom.xml文件)。这里的顶级意味着这些项目位于存储库根目录下的子目录中。所有这些项目应该保留在同一个Git仓库中。

  repo 
+ --- projectA
+ --- pom.xml

+ --- projectB
+ --- pom.xml

他们可以/应该由独立jenkins工作来构建。所以我们为projectA和projectB提供了一个工作。

以前在Subversion中,我能够为每个项目设置一个Jenkins作业(仅用于检出项目)然后从pom.xml运行一个Maven构建。



使用Git模型(可能与所有DVCS相同),这个变化并且我不确定什么是最好的实践。有几个选项,我看到并从中没有我真正喜欢的:


  1. 每个Jenkins作业都是配置克隆/拉动完整的Git repo和
    引用Maven构建的/pom.xml。所以
    这个工作包含所有的代码,但只是构建它的一部分。

  2. Git提供子模块( http://book.git -
    似乎有点棘手(可以轻松破解)

  3. 创建一个maven父级(聚合器包含所有的项目)项目
    触发每个项目构建(有一个詹金斯工作)。这个pom.xml包含了projectA和projectB的元素。

您是否看到过更有用的方法(非常典型的设置)。你有什么经验?任何最佳实践?

我认为你在这里对付谷物。如果这些项目是作为版本化单元发布的,那么确实应该创建一个父POM。但你应该只有一份CI工作。如果你想快速构建,你可以将它配置为仅构建自上一次构建以来发生更改的模块(构建部分中的高级按钮 - 增量构建 - 仅构建更改的模块)。您也可以告诉Jenkins如果需要执行并发构建来一次测试多个提交。



但我很好奇为什么你认为你需要多个CI作业?如果你认为这两个项目有不同的生命周期,或许它们应该单独进行版本化,因此应该放在独立的git存储库中。不要保存git存储库,它们很便宜。事实上,几乎每一种情况下都越多越好。

通常,您希望给定的pom生成单个工件。 Aggregator poms对于将大型工件的一部分分解为子模块非常有用,但前提是这些子模块不是自行发布的。

I have a Git repository that contains a bunch of top-level maven projects (each sits in their own sub-directory with a pom.xml). Top-level here means that these projects sit in subdirectory directly underneath the repository root. All of these projects should remain in the same Git repository.

repo
+--- projectA
    +--- pom.xml

+--- projectB
    +--- pom.xml

They can/should be built by independent jenkins jobs. So we have a job for projectA and one for projectB.

Formerly with Subversion I was able to set up a Jenkins job (for each project) that would checkout only the project source and run a Maven build from the pom.xml.

With the Git model (probably the same with all DVCS) this changes and I'm not sure what is best practice. There are a few options that I see and from which none I really like:

  1. Each Jenkins job is configured to clone/pull the full Git repo and refers to the /pom.xml for the Maven build. So the job has all the code but builds only a slice of it.
  2. Git offers Submodules (http://book.git-scm.com/5_submodules.html) which seem to be a bit tricky to handle (and can break easily)
  3. Create a maven parent (aggregator that contains all of the projects) project that triggers each projects build (having a single jenkins job). This pom.xml contains elements for projectA and projectB.

Do you see any more useful approach for this (very typical setup). What is your experience? Any best practices?

解决方案

I think you're working against the grain here. If these projects are released as a versioned unit, you should indeed create a parent POM. But you should probably only have a single CI job. If you want that build to go quickly, you can configure it to only build modules which have changed since the last build (advanced button in Build section - "Incremental build - only build changed modules"). You can also tell Jenkins to "Execute concurrent builds if necessary" to test multiple commits at once.

But I'm curious why you think you want multiple CI jobs? If you perceive that these two projects have different lifecycles, perhaps they should be versioned seperately and should therefore be in seperate git repositories. Don't conserve git repositories, they are cheap. In fact, the more the merrier in almost every case.

Usually, you want a given pom to produce a single artifact. Aggregator poms are useful for breaking up parts of a larger artifact into submodules, but only if those submodules aren't released on their own.

这篇关于Jenkins:如何从git存储库构建多个顶级项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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