简体   繁体   English

詹金斯·哈德森(Jenkins Hudson)建造问题

[英]Jenkins Hudson Build Issue

I am new to Nexus and Ant. 我是Nexus和Ant的新手。 I have success in generating components through Jenkin Hudson build jobs that are ant driven. 我通过詹金·哈德森(Jenkin Hudson)构建受蚂蚁驱动的工作来成功生成组件。 We have SVN as the source repository. 我们将SVN作为源存储库。

The issue here is that, all the components are getting created again into the nexus repository when I am running the Hudson job. 这里的问题是,当我运行Hudson作业时,所有组件都会再次创建到nexus存储库中。 Lets say I have 5 jars in my applications and I have change in only one class file corresponding to a specific jar. 可以说我的应用程序中有5个jar,并且仅在对应于特定jar的一个类文件中进行了更改。 Instead of creating only the jar that is having the change, all 5 jars are getting created every time. 而不是仅创建具有更改的jar,而是每次都创建所有5个jar。

Is there some settings as Jenkins that will help me achieve what I am looking for .. Or is this something that needs to be controlled through ant build.xml ? Jenkins是否有一些设置可以帮助我实现所需的设置?还是需要通过ant build.xml进行控制?

Appreciate your help in advance. 提前感谢您的帮助。

There's a bit more to your setup than you allow us to know. 您的设置所包含的内容比您让我们知道的要多。

First, you say Ant , but you're using a Maven repository. 首先,您说Ant ,但是您正在使用Maven存储库。 Are you using Ivy? 您在使用常春藤吗? Or, do you use the <wget> task to download the jars? 或者,您是否使用<wget>任务下载罐子?

How do you deploy your jars to your Maven repository? 如何 jar 部署到Maven存储库? Do you use an Ant plugin, a Jenkins plugin, or do you use mvn deploy:deploy-file ? 您使用Ant插件,Jenkins插件还是使用mvn deploy:deploy-file Do you do this in your Jenkins job definition or do you use something like the Promoted Build Plugin or Repository Connector Plugin ? 您是在Jenkins工作定义中执行此操作,还是使用诸如Promoted Build插件Repository Connector插件之类的工具

Finally, what exactly is the problem? 最后,到底是什么问题? Is it a problem with deploying jars to your Nexus repository? 将jar部署到Nexus存储库是否有问题? Is it a problem with the Jenkins job rebuilding all five jars? 詹金斯(Jenkins)的工作是重建所有五个罐子吗? And, why is this a problem? 而且,为什么这是一个问题? What are the issues if a jar is redeployed to your Nexus repository? 如果将罐子重新部署到Nexus存储库中,会出现什么问题? Does it take too much time? 需要太多时间吗? Can you configure Nexus not to run the deploy if the checksum of the jar has not changed? 如果jar的校验和未更改,是否可以将Nexus配置为不运行部署?

Also, why are you building five jars in one project. 另外,为什么要在一个项目中建造五个罐子。 Could you make it five separate Jenkins jobs, and only build jars where the source gets changed? 您能否将它做成五个单独的Jenkins作业,并且仅在更改源的地方构建jars?


Addendum 附录

Application builds a single war and bunch of jars that are external to the war. 应用程序会建立一次战争以及战争外部的一堆罐子。 They remain outside the war. 他们仍然在战争之外。 I have a java web application XXX. 我有一个Java Web应用程序XXX。 On running the build job on this application, I will get abc.war and aaa.jar, bbb.jar, ccc.jar. 在此应用程序上运行构建作业时,我将得到abc.war和aaa.jar,bbb.jar,ccc.jar。 There jars to be created are mentioned in the build.xml. build.xml中提到了要创建的jar。

Here's how we handle this issue. 这是我们处理此问题的方法。 It may take a bit of setup for you. 您可能需要一些设置。

First, we use Ivy with Ant. 首先,我们将Ivy与Ant结合使用。 Ivy allows us to use Maven dependency management without having to completely restructure our build process. Ivy允许我们使用Maven依赖管理,而不必完全重组我们的构建过程。

Each jar is a separate project in our Jenkins server. 每个jar是我们Jenkins服务器中的一个单独项目。 The jar gets rebuilt when the code for that jar is changed. 更改该jar的代码后,将重新构建该jar。 Not knowing how your repository and projects are structured, it may be harder for you to do this. 不知道您的存储库和项目的结构,您可能很难做到这一点。

If your war is setup to call separate build.xml for each jar, it shouldn't be too hard to do this. 如果您的战争设置为每个jar分别调用build.xml,那么这样做就不难了。 If you have a single build.xml, but separate targets for each jar, and each jar has its source code in a separate tree, it'll be a bit tricker. 如果您只有一个build.xml,但是每个jar都有各自的目标,并且每个jar的源代码都位于单独的树中,那将有些麻烦。 You can setup Jenkins to checkout/update the entire project source code, but only look at the source code in a particular directory to see if a rebuild is necessary. 您可以将Jenkins设置为签出/更新整个项目源代码,但仅查看特定目录中的源代码以查看是否需要重建。 If the source code for all the jars are intermingled in a complex way, it'll be harder to do. 如果所有jar的源代码以复杂的方式混合在一起,则将变得更加困难。

We use the Jenkins Promoted Build Plugin to deploy the built jar to our Maven repository. 我们使用Jenkins Promoted构建插件将构建的jar部署到我们的Maven存储库。 This gives us a bit more flexibility to decide when jars are deployed. 这使我们可以更灵活地决定何时部署jar。 Our standard practice is to deploy snapshot versions after each build (to let developers play around with the latest features), but use release versions in our war. 我们的标准做法是在每次构建后都部署快照版本(以使开发人员可以使用最新功能),但在战争中使用发行版。

When a new release of a jar is deployed, we set it up, so that any project that depends upon that war is automatically rebuilt. 部署新版本的jar时,我们对其进行了设置,以便自动重建依赖该战争的任何项目。

When we build a war, we don't build the jars, but use <ivy:retrieve> to retrieve the required jars from our repository. 进行战争时,我们不会构建jar,而是使用<ivy:retrieve>从我们的存储库中检索所需的jar。

So: 所以:

  • We only build the jar if the jar's source itself has changed. 我们仅在jar的源本身已更改的情况下构建jar。
  • We build the war by downloading the required jars. 我们通过下载所需的jar来建立战争。 If you don't clean the cache between each build, only changed jars will be downloaded. 如果您不清理每个版本之间的缓存,则只会下载更改过的jar。
  • We setup Jenkins to fire off a war build if one of its dependent jars have been modified. 如果詹金斯(Jenkins)的一个依赖罐子已被修改,我们将其设置为开火。
  • When the war builds, it only downloads the changed jars, and then builds any classes, etc. it has. 当战争爆发时,它只会下载更改后的罐子,然后构建它拥有的任何类,等等。
  • If you structure your project correctly, Ant will only build what was changed. 如果您正确地构建项目,Ant只会构建已更改的内容。 However, we do a clean and Subversion update, so we do rebuild the entire project, but don't have to redownload the entire project. 但是,我们进行了干净的Subversion更新,因此我们确实重建了整个项目,但不必重新下载整个项目。 Since wars only have to download the changed jars, and build what java code they use, it doesn't take a long time to rebuild wars anyway. 由于war只需要下载更改后的jar并构建它们使用的Java代码,因此无论如何都不需要花费很长时间来重建war。

I hope this helps. 我希望这有帮助。

One more thing... 还有一件事...

You can try not cleaning out your build detritus between builds on Jenkins. 您可以尝试在詹金斯(Jenkins)上的构建之间不清除构建碎屑。 Use use updates only in Jenkins to only update source files that haven't been changed. 在Jenkins中使用使用更新来仅更新未更改的源文件。 Ant will automatically not rebuild stuff that hasn't been changed. Ant不会自动重建未更改的内容。 This means that unchanged *.java files won't recompile, and *.jar files won't rebuild if their components haven't changed. 这意味着未更改的*.java文件将不会重新编译,并且*.jar文件如果其组件未更改也不会重建。

However, you must make sure your build.xml is bullet proof and well structured. 但是,您必须确保build.xml是防弹的并且结构合理。 Otherwise, you'll end up with a lot of hurt. 否则,您将遭受很多伤害。 The first six months at my current work, I rewrote all of the build.xml files to make sure they were well structured and will do build avoidance. 在当前工作的前六个月中,我重写了所有build.xml文件,以确保它们的结构合理并且可以避免构建。 You may have a lot of work to get this to work correctly. 您可能需要做很多工作才能使其正常工作。

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

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