简体   繁体   English

沙盒Maven基于Jenkins

[英]Sandboxed Maven builds on Jenkins

I am trying to find a solution for the following puzzle. 我正在尝试为以下难题找到解决方案。 I have java projects, managed by maven, which needs some native dependencies to work (run unit and integration tests). 我有由maven管理的Java项目,该项目需要一些本机依赖项才能运行(运行单元和集成测试)。 Those are provided in form of deb packages, which needs to be installed prior to running a build. 这些以deb软件包的形式提供,需要在运行构建之前安装。

I use Jenkins for CI. 我将詹金斯用于CI。 Native dependencies can not be installed on Jenkins nodes, because of conflicts with other builds and they can change often. 本地依赖项无法安装在Jenkins节点上,因为与其他内部版本存在冲突,并且它们经常更改。 What I do now is not to create a Jenkins job type 'maven', but 'freestyle' and use a pbuilder to create an clean sandbox, install all that is necessary and invoke maven build. 我现在要做的不是创建Jenkins作业类型“ maven”,而是创建“ freestyle”并使用pbuilder创建一个干净的沙箱,安装所有必需的组件并调用maven build。

This is working great, but I am loosing Jenkins maven goodies like automatic upstream projects, trigger build when dependency change, etc. Jenkins simply does not know that maven is there. 这很有效,但是我失去了Jenkins的maven好东西,例如自动上游项目,在依赖项更改时触发构建等。Jenkins根本不知道maven在那儿。

Finally, my question. 最后,我的问题。 Is there a way how to achieve both, isolate build so installed libraries does not affect other builds and leverage Jenkins's 'magic' applied to maven builds and their dependencies? 有没有办法实现这两个目标,隔离构建,使已安装的库不影响其他构建,并利用Jenkins应用于Maven构建及其依赖项的“魔力”?

You could split your build in three jobs, which trigger the next one. 您可以将构建分为三个作业,这将触发下一个作业。

  1. Create needed environment 创建所需的环境
  2. Run maven job 运行Maven工作
  3. Clean Up 清理

The problem can be solved by using distributed Jenkins builds. 使用分布式Jenkins构建可以解决该问题。 Slave agents can be configured to provision clean environment (eg via VMs, docker,...) for each build and tear it down after build is done. 可以配置从属代理为每个构建提供干净的环境(例如,通过VM,docker等),并在构建完成后将其拆除。 This way Jenkins job can be of Maven type and any changes done by pre-build step will not affect others. 这样,詹金斯的工作可以是Maven类型的,并且预构建步骤所做的任何更改都不会影响其他人。

More information can be found here . 可以在此处找到更多信息。

Consider docker. 考虑码头工人。 There you can run processes in isolated environments just as you want. 在那里,您可以根据需要在隔离的环境中运行流程。 Docker works in a way that it easily communicates with Jenkins. Docker的工作方式可轻松与Jenkins进行通信。

As a benefit you can also use that docker container to run local builds in the same environment as they run in Jenkins. 作为一项好处,您还可以使用该Docker容器在与Jenkins中运行的环境相同的环境中运行本地构建。

Even a Freestyle job has "Invoke top-level Maven targets". 即使是Freestyle作业也具有“调用顶级Maven目标”。 You could use that to get "maven goodies" while also having ability to run other build steps. 您可以使用它来获得“ maven好东西”,同时还具有运行其他构建步骤的能力。

There is an option to "use private Maven repository" which will make sure it will use the .m2/repository folder location relative to the workspace. 有一个“使用私有Maven存储库”选项,可以确保它使用相对于工作区的.m2/repository文件夹位置。 If you need to separate into multiple jobs, you can use "Custom/shared workspace" between those jobs. 如果需要分成多个作业,则可以在这些作业之间使用“自定义/共享工作区”。

Even in Maven-style job, there is an option to use private repository, so that one job does not affect another. 即使在Maven风格的作业中,也可以使用私有存储库,因此一个作业不会影响另一个作业。

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

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