Best practice to build a CD pipeline to deploy application to different environments

Currently I'm trying to build a CD pipeline for our application, which is a typical Maven J2EE project and we'll deploy a war to Tomcat container.

Our plan for the CD pipeline looks like this:

CI(Run UT and build the WAR) -> Deploy to DEV -> Deploy to SIT -> Deploy UAT -> Deploy PROD

To follow the best practices of CD, we only build the binary(war) once in the CI phase, but we have some configuration files which are different for each environment, so what's the best way to put the related configuration files for each environment during the deployment phase?

We're using Jenkins and the build-pipe-line plugin to build the pipeline, are there any recommended plugins to make this happen?

Thanks.

Answers


Configuring the artifact

  • Write a script to replace the config files if they're embedded in the WAR.

You may employ maven-antrun-plugin to

  1. Extract the WAR
  2. Replace the config
  3. Repack the WAR

The ant task should be reused for different environments:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
    <tasks>
        <echo message="Configuring artifact, ${PIPELINE_STAGE}"/>
        <!-- extracting,replacing,repacking -->
    </tasks>
</configuration?
  • Externalize the config files. Well, just upload the config files to the server.

Sharing the artifact through pipeline stages

  1. Upload the WAR to your artifact repository.
  2. Dowload the WAR built in your CI stage and configure it.
  3. Deploy the configured WAR.

You may find the detail in the Sharing build artifacts throughout the pipeline from this article.


Just to complete the number of possible answers:

You could use the maven assembly plugin to create different deployment war files. From my experience this is much nicer than using ant-tasks for that.


Need Your Help

Nested Array Foreach Issue

php arrays loops foreach

I am very basic new php learner, i having difficulty to get nested array value, here is my json result:

Regular expressions in Smart Mobile Studio

javascript regex delphi smart-mobile-studio

How do I work with regular expressions in Smart Mobile Studio? For example, how do I code following example in Object Pascal?