mchinaloy
mchinaloy

Reputation: 1494

Jenkins building for different environments

I currently have a Jenkins instance installed on a Development box. 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).

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?

(Note I am also using Maven in my project).

Upvotes: 3

Views: 5852

Answers (2)

treeno
treeno

Reputation: 2600

I know 3 options:

  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.

  2. Another Option is mavens assembly-plugin. That can be used together with the release-plugin, as far as I know.

  3. We decided to write a simple tool that changes the war-files after the maven-build process. It runs in a seperate 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. And if we need the configuration for the production release we start a jenkins job that does the configuration of the war-files.

Upvotes: 2

Kent
Kent

Reputation: 195229

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.

You may want to check maven profile, maven resource filtering for detailed configuration.

something not related, connect Database via jndi if possible.

Upvotes: 1

Related Questions