java Jenkins:使用子项目构建项目的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15109495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:30:06  来源:igfitidea点击:

Jenkins: best way to build a project with sub projects

javajenkins

提问by Michael

We have a project with two subprojects in the same SVN repository. For example:

我们在同一个 SVN 存储库中有一个包含两个子项目的项目。例如:

svn://ip/svn/ trunk/subproject1
svn://ip/svn/ trunk/subproject2

The build for project should include results of builds of both subprojects. To make our build faster, I want to run build of subproject1 only if SVN was changed respectively (in the svn://ip/svn/ trunk/subproject1). Similarly for subproject2

项目的构建应包括两个子项目的构建结果。为了使我们的构建更快,我想仅在 SVN 分别更改时(在 svn://ip/svn/trunk/subproject1 中)运行 subproject1 的构建。子项目2类似

What is the best way to do it? Can I do it with a single job? How should I define build triggers in this case?

最好的方法是什么?我可以用一份工作做吗?在这种情况下,我应该如何定义构建触发器?

Or I need to define 3 jobs: one for each subproject or one for each project?

或者我需要定义 3 个工作:每个子项目一个还是每个项目一个?

Any help will be appreciated! Best regards, Michael

任何帮助将不胜感激!最好的问候,迈克尔

回答by ben.snape

There are various ways you can achieve this using Jenkins.

您可以通过多种方式使用 Jenkins 实现这一点。

  1. The multi-SCM pluginwill allow - as the name suggests - to include multiple source repositories in a single job.

  2. You can define njobs which trigger each other (i.e. have a dependency on each other). You can find this under Build Triggers> Build after other projects are built.

  3. There is also the option of a master job controlling the downstream jobs. You'll find this option under Post-build Actions> Build other projects.

  1. 顾名思义,多 SCM 插件将允许在单个作业中包含多个源存储库。

  2. 您可以定义n相互触发的作业(即相互依赖)。您可以在Build Triggers>下找到它Build after other projects are built

  3. 还有一个主作业控制下游作业的选项。您会在Post-build Actions>下找到此选项Build other projects

With regard to build triggering, you can use the poll SCMoption. It's not the most efficient methodbut your options may be limited with SVN rather than Git.

关于构建触发,您可以使用该poll SCM选项。这不是最有效的方法,但您的选择可能会受到 SVN 而不是 Git 的限制。

I just noticed you also mentioned collating results from all builds - you can achieve this either by having a single job or by using the option aggregate downstream test resultsunder Post-build Actions.

我只注意到你也提到整理所有构建结果-您可以通过将单个作业或使用选择,要么实现这一目标aggregate downstream test results之下Post-build Actions

Ultimately, you need to be clear on your build strategy. It sounds to me that you want to ensure that nothing is broken if a change has been made to either sub-project. I'm not sure how well the multi-SCM plugin copes with the concept of polling multiple repositories so you may need to factor that in.

最终,您需要明确您的构建策略。在我看来,如果对任何一个子项目进行了更改,您都希望确保不会有任何问题。我不确定多 SCM 插件如何处理轮询多个存储库的概念,因此您可能需要将其考虑在内。

I think I've given you a few options to try out; let me know how you get on.

我想我已经给了你一些尝试的选择;让我知道你是怎么办的。

回答by Ramón Rial

This is an old thread (18 months) but a few days ago the Jenkins multijob plugin has released a new version that incorporates an option that allows triggering a build only when scm changed since last build:

这是一个旧线程(18 个月),但几天前 Jenkins 多任务插件发布了一个新版本,其中包含一个选项,该选项允许仅在自上次构建以来 scm 发生更改时触发构建:

This is the Build only if SCM changes.

这是仅当 SCM 更改时才构建

There is also an option to force the build regardless of this option.

无论此选项如何,还有一个选项可以强制构建。

回答by razz0

There is also a Multijob Pluginavailable for Jenkins. You can use it to run your sub project builds hierarchically in one main project.

还有一个适用于 Jenkins的Multijob Plugin。您可以使用它在一个主项目中分层运行您的子项目构建。

回答by lily LIU

I have no idea about how to set with SVN, but with GITyou can set Additional Behaviourson Source Code Management step.

我不知道如何使用 SVN 进行设置,但是使用GIT,您可以在源代码管理步骤中设置附加行为

Choose Polling ignores commits in certain paths, then set the Included Regions. This setting can filter other sub project commits within the same git repository.

选择轮询忽略某些路径中的提交,然后设置包含的区域。此设置可以过滤同一 git 存储库中的其他子项目提交。

Also do setting on Build Triggersstep, tick Poll SCMand leave Scheduleblank.

还要在Build Triggers步骤中进行设置,勾选Poll SCM并将Schedule留空。

If want to set auto deployment, you may need to set web hookon git repository side.

如果要设置自动部署,您可能需要在 git 存储库端设置web hook

Jenkins version is 2.32 and Jenkins Git plugins

Jenkins 版本是 2.32 和Jenkins Git 插件