简体   繁体   English

使用Jenkins构建依赖项目

[英]Building dependent projects using Jenkins

Lets say i have 3 ANT projects each with its build.xml script located at the top level folder 假设我有3个ANT项目,每个项目的build.xml脚本都位于顶级文件夹中

proj1
 file1.java
proj2
 file2.java
proj3
 file3.java

I configured Jenkins to build these 3 projects and it builds them and stores the output in three separate folders. 我将Jenkins配置为构建这3个项目,并构建它们并将输出存储在三个单独的文件夹中。

/output/proj1/2012-02-28_20-11-06/proj1/distribution/proj1.jar
/output/proj2/2012-02-28_20-11-08/proj2/distribution/proj2.jar
/output/proj3/2012-02-28_20-11-09/proj3/distribution/proj3.jar

The ANT script is the one that puts the jar file in the distribution folder. ANT脚本是将jar文件放在分发文件夹中的脚本。 I want to use these jar files in another project which produces a war file. 我想在另一个生成war文件的项目中使用这些jar文件。

The jar files that are generated in each project are used to build a WAR file. 每个项目中生成的jar文件用于构建WAR文件。 Is there any way i can configure Jenkins to build proj1, proj2, proj3 then copy the jar files to a specific location which will contain another ANT project which when run will produce a war file? 有没有办法我可以配置Jenkins来构建proj1,proj2,proj3然后将jar文件复制到一个特定的位置,该位置将包含另一个ANT项目,该项目在运行时会产生一个war文件? Or does this have to be coded with ANT? 或者这是否必须用ANT编码?

Also, is it possible to configure jenkins to do multiple checkouts before running the ANT build script. 此外,是否可以在运行ANT构建脚本之前配置jenkins进行多次检出。 I am using CVS and would like to do 3 checkouts each using a different tag before running the build. 我正在使用CVS,并希望在运行构建之前使用不同的标记执行3次检出。

Edit 编辑

I posted the question last night before i went to bed. 我在睡觉前昨晚发布了这个问题。 Reading it again today i think it is not clear enough so i will clarify the requirement again. 今天再读一遍,我认为还不够清楚,所以我会再次澄清这个要求。 I have 4 projects that use ANT as the build mechanism and are all stored in a CVS repository. 我有4个项目使用ANT作为构建机制,并且都存储在CVS存储库中。 All 4 projects when built form a WAR file that is deployed on a Tomcat application server. 构建的所有4个项目形成一个部署在Tomcat应用程序服务器上的WAR文件。

proj1
 - file1.java
 - file2.java

proj2
 - file3.java
 - file4.java

proj3
 - file3.java
 - file4.java

proj4
  - jsp
    - home.jsp
 - css
    - home.css
  - WEB-INF
     - lib
     - classes 
    - web.xml

Each project (except proj4) has an ANT build file which builds the project and produces a JAR file which it stores in a 'distribution' folder on the root folder of the project. 每个项目(proj4除外)都有一个ANT构建文件,用于构建项目并生成一个JAR文件,该文件存储在项目根文件夹的“distribution”文件夹中。 For example after proj1 is built it will look like this 例如,在构建proj1之后,它将如下所示

proj1
 - file1.java
 - file2.java
 - distribution
      - classes
           - file1.class
           - file2.class
      - proj1.jar

Proj4 has a dependency on proj1, proj2 and proj3 in that it first needs to copy all the jar files into its workarea before it builds a war file. Proj4依赖于proj1,proj2和proj3,因为它首先需要在构建war文件之前将所有jar文件复制到其工作区。 The ANT build file for project4 copies the JAR files from proj1, 2 and 3 and builds a WAR files. project4的ANT构建文件从proj1,2和3复制JAR文件并构建WAR文件。 The resulting WAR file contains the following structure 生成的WAR文件包含以下结构

proj4
  - jsp
    - home.jsp
 - css
    - home.css
  - WEB-INF
    - lib
       - proj1.jar
       - proj2.jar
       - proj3.jar
    - classes 
    - web.xml  

Now to automate the above i need to somehow configure Jenkins and ANT to do the following (in the order shown) 现在自动执行上述操作我需要以某种方式配置Jenkins和ANT来执行以下操作(按所示顺序)

- Checkout proj1 from CVS using RELEASE1.1 tag
- Build proj1

- Checkout proj2 from CVS using RELEASE1.2 tag
- Build proj2

- Checkout proj3 from CVS using RELEASE1.1 tag
- Build proj3

- Checkout proj4 from CVS using RELEASE1.1 tag
- Copy the proj1.jar, proj2.jar, proj3.jar from the previous 3 builds and copy them to the proj4 WEB-INF/lib folder.
- Build proj4
- Deploy the WAR file. 

I played around with Jenkins yesterday and managed to configure it to build each of the projects but each jar file ends up in an unrelated folder. 昨天我和Jenkins一起玩,并设法配置它来构建每个项目,但每个jar文件最终都在一个不相关的文件夹中。 How can i configure Jenkins to build the projects as i've described above? 我如何配置Jenkins来构建项目,如上所述?

The environment has the following properties 环境具有以下属性

Build tool - ANT
OS - Solaris

Maven would probably work with this but at the moment there are no plans to introduce Maven. Maven可能会使用它,但目前还没有计划引入Maven。 If there is a simple Maven like build tool that i can use to just store the libraries i need that does not require external access then please let me know. 如果有一个简单的Maven之类的构建工具,我可以使用它来存储我需要的库,不需要外部访问,请告诉我。

Thanks in advance. 提前致谢。

I do not understand exactly what your requirements are, but let's give it a shot: 我不明白你的要求是什么,但让我们试一试:

Start your three jobs from a single job (lets call it TriggerJob ) using Parameterized Trigger Plugin as a build step. 使用参数化触发器插件作为构建步骤,从单个作业(称为TriggerJob )启动三个作业。 Give them TriggerJob 's BUILD_ID as a parameter, which they'll use to store the results (instead of using their own BUILD_ID's; if you still need to build them separately sometimes - without being triggered from TriggerJob - you can specify some default value for the parameter, and check for it with Conditional BuildStep Plugin , when it has the default value - use own BUILD_ID, otherwise use the parameter passed in). 给他们TriggerJobBUILD_ID作为参数,他们将用它来存储结果(而不是使用他们自己的BUILD_ID;如果你仍然需要单独构建它们 - 而不是从TriggerJob触发 - 你可以指定一些默认值参数,并使用条件BuildStep插件检查它,当它具有默认值时 - 使用自己的BUILD_ID,否则使用传入的参数)。

Make TriggerJob wait for the three jobs to finish, then collect your jar's ( TriggerJob knows where they are), and proceed with the fourth job that will call your last ANT to archive them together (or make it into an ANT build step in TriggerJob , whatever fits better). TriggerJob等待三个作业完成,然后收集你的jar( TriggerJob知道它们在哪里),然后继续第四个作业,它将调用你的最后一个ANT将它们归档在一起(或者将它变成TriggerJob中的ANT构建步骤,什么适合更好)。

Just in case the following observation may prove useful for you: every ANT build step can use its own build file (it's under ADVANCED button). 以防万一以下观察结果可能对您有用:每个ANT构建步骤都可以使用自己的构建文件(它位于ADVANCED按钮下)。 You can use environment variables to specify its path. 您可以使用环境变量指定其路径。

Multiple checkouts: I'm not familiar with CVS plugin, but with Subversion plugin I prefer to do things by hand: I have trigger jobs that poll SVN via Subversion Plugin and pass revision numbers as parameters to jobs that do actual work. 多次检查:我不熟悉CVS插件,但是使用Subversion插件我更喜欢手工操作:我有触发作业通过Subversion插件轮询SVN并将修订号作为参数传递给实际工作的作业。 Those jobs then use explicit SVN calls (from shell build steps) to update to revisions passed as parameters. 然后,这些作业使用显式SVN调用(从shell构建步骤)更新为作为参数传递的修订。 Maybe you can do the same thing with CVS plugin. 也许你可以用CVS插件做同样的事情。

Use Apache Ivy with proj1, proj2 and proj3 publishing their jar files to an artifact repository. 使用Apache Ivy和proj1,proj2和proj3将他们的jar文件发布到工件库。 You can then proj4 triggered, whenever you publish a new version of proj1, proj2 or proj3 (eg, using the Jenkins Ivy Plugin ). 每当你发布proj1,proj2或proj3的新版本时(例如,使用Jenkins Ivy插件 ),你就可以触发proj4。 Proj4 again uses Ivy, but this time to retrieve the proj1, proj2 and proj3 jars as dependencies, which are then used to build the WAR (which you would also publish to your repository). Proj4再次使用Ivy,但这次要检索proj1,proj2和proj3 jar作为依赖项,然后用于构建WAR(您也将发布到您的存储库)。

If you are feeling confident, you can also consider switching from Ant to Gradle , which also uses Ivy under the covers. 如果你有信心,你也可以考虑从Ant转换到Gradle ,它也使用常春藤。 You might also consider Maven , but I'm not familiar enough with it to recommend it. 您可能也会考虑Maven ,但我对它的推荐并不熟悉。 I've heard a lot of people swear by it and a lot of people swear at it. 我听说很多人都发誓,很多人都发誓。

Here is a similar question and answer 这是一个类似的问题和答案

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

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