如何在使用 Ant/Jenkins 时检出同一 Java 项目的不同 Subversion 标签/分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11011358/
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 03:25:22  来源:igfitidea点击:

How can I checkout different Subversion tags/branches of the same Java project while using Ant/Jenkins?

javajenkinssvnsvn-checkout

提问by Alain

Here is my dev configuration:

Under Subversion,

- I have my project_X/trunk (with my latest dev),
- I have my project_X/tags (with different releases),
- I am thinking of adding a branch folder.

I am using Jenkins to build my project_X/trunk using an Ant script. My Ant script does many things, it checks-out, compiles, creates the documentation with graphs, runs the unit tests, performs pmd, creates a jar and zips everything.

这是我的开发配置:

在 Subversion 下,

-我有我的 project_X/trunk(与我的最新开发),
-我有我的 project_X/tags(具有不同的版本),
-我正在考虑添加一个分支文件夹。

我正在使用 Jenkins 使用 Ant 脚本构建我的 project_X/trunk。我的 Ant 脚本做了很多事情,它检查、编译、创建带有图形的文档、运行单元测试、执行 pmd、创建一个 jar 并压缩所有内容。

I would like to be able to use my Ant script on tags or branches (as well as the trunk) for the same Project.

What's the easiest way to do this:

I think it is just a question of checking out the right path to the Subversion repository, Right?

- If I am correct, I should make the path to the Subversion dynamic.
- In my Ant script should my Subversion path be a variable?
- How do I pass the path value from Jenkins' interface?
- Is there a plugin that lets me pass the Subversion path value from Jenkins to the Ant script?
- Or should I just create a new job in Jenkins (with the same script but different path)?

我希望能够在同一个项目的标签或分支(以及主干)上使用我的 Ant 脚本。

最简单的方法是什么:

我认为这只是检查 Subversion 存储库的正确路径的问题,对吗?

- 如果我是对的,我应该使 Subversion 的路径动态化。
- 在我的 Ant 脚本中,我的 Subversion 路径应该是一个变量吗?
- 如何从 Jenkins 的界面传递路径值?
- 是否有插件可以让我将 Subversion 路径值从 Jenkins 传递到 Ant 脚本?
- 或者我应该在 Jenkins 中创建一个新工作(使用相同的脚本但不同的路径)?

Hope

希望

Thanks in advance for your help,
Best regards,

预先感谢您的帮助,
最好的问候,

回答by malenkiy_scot

You should parameterize your build by tag/branch name. The easiest way to do it is to add a parameter (say, SVN_BRANCH_DIR) to your Jenkins job which will have values such as trunk, branches/branch1, tags/sometag.

您应该通过标签/分支名称参数化您的构建。最简单的方法是向您的 Jenkins 作业添加一个参数(例如SVN_BRANCH_DIR),该参数将具有诸如trunk, branches/branch1, 之类的值tags/sometag

Now, if you use Jenkins ANT build step that parameter will be passed automatically to your ANT script as a property (by way of ANT -Doption). So you can use ${SVN_BRANCH_DIR}in it (e.g. svn://myserver/myrepo/${SVN_BRANCH_DIR}).

现在,如果您使用 Jenkins ANT 构建步骤,该参数将作为属性自动传递给您的 ANT 脚本(通过 ANT-D选项)。所以你可以${SVN_BRANCH_DIR}在其中使用(例如svn://myserver/myrepo/${SVN_BRANCH_DIR})。

回答by theTestTube

Jenkins Subversion Pluginprovides a "List subversion tags (and more)" project parameter since Version 1.24 (Mar 22, 2011).

自 1.24 版(2011 年 3 月 22 日)起,Jenkins Subversion 插件提供了“列出 subversion 标签(及更多)”项目参数。

Literally,

字面上地,

When used, this parameter will display a field at build-time so that the user is able to select a Subversion tag from which to create the working copy for this project. Once the two fields Name and Repository URL are set, you must (1) ensure the job uses Subversion and (2) set the Repository URL field of Subversion by concatenating the two fields of this parameter. For instance, if Name is set to SVN_TAG and Repository URL is set to https://svn.jenkins-ci.org/tags, then Subversion's Repository URL must be set to https://svn.jenkins-ci.org/tags/$SVN_TAG. Notice that you can set the Repository URL field to a Subversion repository root rather than just pointing to a tags dir (ie, you can set it to https://svn.jenkins-ci.orgrather than https://svn.jenkins-ci.org/tags). In that case, if this repository root contains the trunk, branches and tags folders, then the dropdown will allow the user to pick the trunk, or a branch, or a tag.

使用时,此参数将在构建时显示一个字段,以便用户能够选择一个 Subversion 标记,从中创建该项目的工作副本。设置 Name 和 Repository URL 两个字段后,您必须 (1) 确保作业使用 Subversion 和 (2) 通过连接此参数的两个字段来设置 Subversion 的 Repository URL 字段。例如,如果 Name 设置为 SVN_TAG 并且 Repository URL 设置为https://svn.jenkins-ci.org/tags,那么 Subversion 的 Repository URL 必须设置为https://svn.jenkins-ci.org/tags /$SVN_TAG。请注意,您可以将 Repository URL 字段设置为 Subversion 存储库根目录,而不仅仅是指向标签目录(即,您可以将其设置为https://svn.jenkins-ci.org而不是https://svn.jenkins-ci.org/tags)。在这种情况下,如果此存储库根目录包含主干、分支和标签文件夹,则下拉菜单将允许用户选择主干、分支或标签。

For unattended integration builds you could use the default "trunk" parameter value.

对于无人参与的集成构建,您可以使用默认的“trunk”参数值。

I hope this helps.

我希望这有帮助。