使用Maven和Jenkins分阶段部署快照工件 [英] Staged deployment of snapshot artifacts with Maven and Jenkins
问题描述
问题描述
我们有几个相互依赖的多模块项目.像这样:
- 消息传递
- 框架
- 其他组件
他们有单独的源代码控制存储库,并且可以说消息和 othercomponent 中的子模块正在使用来自 framework 子模块的捆绑软件.所有项目都是基于OSGI的多模块Maven项目.它们全部都有一个服务器部分和一个来源GUI部分(Eclipse RAP + RCP).因此,对于所有这些多模块项目,这最终都基于基于Maven的三步构建(因为Tycho构建不能与普通的旧Maven构建混在一起):
- 构建服务器部分
- 构建RAP GUI部件
- 构建RCP GUI部分
最后还有一个最终产品多模块maven项目(简称为我们的产品),该项目使用消息,框架和其他组件.项目我们的产品与其他三个具有相同版本号的版本号不同.
我们使用Jenkins构建了整个系统,并且作业之间的依赖关系树相互触发.该公司决定使用快照在3个框架项目开发人员和我们的产品开发人员之间获取更直接,更快速的反馈.这可能是一个不错的主意,但是存在很大的问题.
如果在构建链中发生了某些故障,则快照存储库将包含无法一起工作的消息,框架和其他组件的快照.这样,我们的产品的开发人员就必须等待有效的快照集(否则他们甚至无法编译一段时间).另一个问题是,在构建期间,快照集也不一致.
想法
对于消息,框架和其他组件,詹金斯(Jenkins)中有明确的最终工作.如果完成,则快照组必须正常工作,因此我们的产品团队可以使用它. 因此,我需要以某种方式收集由构建链创建的快照,并仅在整个构建链成功后才部署快照.
- 是否有这样做的可能性?
我的想法是简单地将作业更改为仅进行 install 而不进行 deploy .然后最后,我可以在本地Maven存储库中查找已构建的快照,并通过脚本进行部署.
- Maven有一些暂存概念(可能仅适用于Nexus pro).它是否说明了快照?
任何想法都值得欢迎.但是我不能改变使用快照的事实.因此说服我使用发行版和快照没有任何用处.
解决方案
我找到了一个不错的解决方法.采取的步骤:
-
构建步骤必须使用 altDeploymentRepository 参数而不是常规目标存储库部署到临时文件夹(请参阅 http://somerepository.com/repositories/snapshots -Dwagon.targetId = idreferredinsettingsxmltogetauthorization
重要提示
旅行车目标应在没有pom文件的文件夹中运行(因此必须在没有项目的情况下运行).否则, fromDir 参数会出现奇怪的错误.
已知限制
- 构建步骤应使用相同的本地存储库运行,因为如果 这些步骤需要其他工件产生的工件,它们可以 在本地存储库中找到它.
- 此解决方案不读取POM来获取应将工件上载到的存储库.今天已将其连接到wagon命令中.但是我现在可以忍受它了:)
Problem Description
We have several multi-module projects which are depending on each other. So something like this:
- messaging
- framework
- othercomponent
They have separate source control repository, and lets say, that submodules inside messaging and othercomponent are using bundles from the submodules of framework. All of the projects are OSGI based multi-module maven projects. All of them have a server part, and a single sourced GUI part (Eclipse RAP+RCP). So this ends up in a three step maven based build for all of these multi-module projects (since Tycho builds cannot be mixed with plain old Maven Builds):
- Building server part
- Building RAP GUI part
- Building RCP GUI part
And finally there is an end product multi-module maven project (lets call it ourproduct), which uses messaging, framework and othercomponent. The project ourproduct has different version number than the other three, which are having a common version number.
We build the whole thing with Jenkins, and the jobs trigger each other depending on the dependency tree. The company decided to use snapshots to get more direct and fast feedback between the 3 framework project developers and the ourproduct developers. This can be a nice idea, however there is a big problem.
If during the building chain something is broken, than the snapshot repository contains snapshots of messaging, framework and othercomponent, which cannot work together. This way the developers of ourproduct have to wait for a working snapshot set (otherwise they cannot even compile some time). An other problem is that during the build the set of snapshots are also not consistent.
Idea
For the messaging, framework and othercomponent there is a definite end job in Jenkins. If that finishes, then the set of snapshots must be working, so the ourproduct team could use it. So i would need to COLLECT somehow the snapshots created by the build chain, and deploy them only if the whole build chain was successful.
- Is there any existing possibility to do this?
My idea was to simply change the jobs to make only install only and not deploy. Then at the end I could look for the built snapshots in the local maven repo, and deploy them by a script.
- There is some Staging Concept for Maven (maybe only with Nexus pro). Does it say anything about snapshots?
Any idea is welcome. However i cannot change the fact of using snapshots. So there is no use in convincing me to use releases and no snapshots.
Solution
I have found a nice workaround. Steps to take:
The build steps have to deploy to a temp folder instead of the normal target repository using the altDeploymentRepository parameter (see http://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html)
mvn deploy -DaltDeploymentRepository=stagingFolder::default::file:///c:/mytempfolder
Run any number of build steps with this setting, and the artifacts are collected in the folder. You can even resume the builds without problem. You can overwrite artifacts (i do not recommend it however)
You have to run the following command after completing all build steps (see http://mojo.codehaus.org/wagon-maven-plugin/copy-mojo.html). This uploads all artifacts which were collected temporarly in the folder:
mvn org.codehaus.mojo:wagon-maven-plugin:copy -Dwagon.source=file:///c:/mytempfolder -Dwagon.target=http://somerepository.com/repositories/snapshots -Dwagon.targetId=idreferredinsettingsxmltogetauthorization
Important Note
The wagon goal should be run in a folder, where there is no pom file (so it must be run without project). Otherwise there is a weird error with the fromDir parameter.
Known Limitations
- The build steps should run using the same local repository, since if the steps need the artifacts produced by other artifacts, they can find it in the local repository.
- This solution does not read the POM to get the repository to which the artifacts should be uploaded. This is wired today into the wagon command. But I can live with it now :)
这篇关于使用Maven和Jenkins分阶段部署快照工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!