简体   繁体   English

詹金斯为不同的环境建设

[英]Jenkins building for different environments

I currently have a Jenkins instance installed on a Development box. 我目前在开发框上安装了Jenkins实例。 This builds fine and deploys to our development environment without any issues. 这种构建很好,并且可以毫无问题地部署到我们的开发环境中。

During the build process my project makes use of a single properties file containing details such as a database connection URL (Details such as these will obviously vary depending on the environment I'm pointing to). 在构建过程中,我的项目使用一个包含详细信息的属性文件,例如数据库连接URL(这些细节显然会因我指向的环境而异)。

What I would like to know is what is the best way to configure my project so that when I want to release to Production the WAR file built by Jenkins contains the Production properties instead of Development? 我想知道的是,配置项目的最佳方法是什么,以便当我想要发布到Production时,Jenkins构建的WAR文件包含Production属性而不是Development?

(Note I am also using Maven in my project). (注意我也在我的项目中使用Maven)。

I know 3 options: 我知道3种选择:

  1. We have used maven.-profiles for that in the past, but they have the disadvantage, that the release-plugin of maven doesn't work with profiles, so we had to change the versions manually and were unable to deploy the artifacts in a remote repository like nexus. 我们过去使用过maven.-profiles,但它们的缺点是maven的release-plugin不能用于配置文件,所以我们不得不手动更改版本而无法将文件部署到像nexus这样的远程存储库。

  2. Another Option is mavens assembly-plugin. 另一个选项是mavens assembly-plugin。 That can be used together with the release-plugin, as far as I know. 据我所知,这可以与release-plugin一起使用。

  3. We decided to write a simple tool that changes the war-files after the maven-build process. 我们决定编写一个简单的工具,在maven-build过程之后更改war文件。 It runs in a seperate Jenkins-Job. 它分开运行Jenkins-Job。 The Idea is, that building and configuring are two seperate steps. 理念是,构建和配置是两个单独的步骤。 The Artifacts comming out of maven are always in a default-configuration. 从maven中传出的工件总是处于默认配置状态。 And if we need the configuration for the production release we start a jenkins job that does the configuration of the war-files. 如果我们需要生产版本的配置,我们会启动一个jenkins作业来完成war文件的配置。

You can create different maven profiles, like dev , prod , then in the profile setting, use/filter the corresponding resource files like .../(dev|test|prod)/project.properties And in Jenkins, when you build for different platform, build with -Pdev or -Pprod to get the war for the right target. 你可以创建不同的maven配置文件,比如devprod ,然后在配置文件设置中,使用/过滤相应的资源文件,如.../(dev|test|prod)/project.properties和Jenkins,当你构建不同的平台,使用-Pdev or -Pprod构建以获得正确目标的战争。

You may want to check maven profile, maven resource filtering for detailed configuration. 您可能需要检查maven配置文件,maven资源过滤以获取详细配置。

something not related, connect Database via jndi if possible. 不相关的东西,如果可能的话,通过jndi连接数据库。

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

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