Make sure you have committed to SCM before Production Build

Maven/BitBucket Validation for Production Code Deployment

Introduction

The justification for this document is to express a way to secure company code and create a possible company standardization for the WAR naming convention that is easily tracked back to a BitBucket commit that was used to deploy an interface to UAT and Production.

By adding a validation step that all code is committed to BitBucket, we circumvent code being accidentally lost on a team member’s laptop.

Example

Example WAR: acsdal-dmdc-mdr-2.0.10.e02cee9.war

The last 7 digits (e02cee9) can be used to track back to BitBucket where the Production Code is, who committed it and when it was last updated.

It works by utilizing the buildnumber-maven-plugin and maven-scm-plugin.

What happens if you try to create a production war file without pushing your code back to BitBucket first? 

Once you commit your code, it will allow a build.

POM Instructions

Modify your POM by updating and adding these code block fields.

<artifactId>your project</artifactId>
<version>2.0.10</version>

<maven-war-pluginversion>3.2.1</maven-war-pluginversion>

Below must be set to your project repository in Bitbucket:

<scm>
<connection>scm:git:https:
//bitbucket.org/your-Org-or-Name/your-project.git
</connection>
<url>https://bitbucket.org/your-Org-or-Name/your-project.git

</url>
</scm>

Add dependency:

<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
</dependency>

Set up a Production Profile. The ${buildNumber} will be added to the end of your WAR file name and is created by the scm plugin.

Make sure to update <outputDirectory> to where you want your WAR file save.

<profile>
<id>prod</id>
<build> <finalName>${project.artifactId}-${project.version}.${buildNumber}
</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<docheck>false</docheck>
<doupdate>false</doupdate>
<shortRevisionLength>7</shortRevisionLength>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-scm-plugin</artifactId>
<version>1.11.2</version>
<executions>
<execution>
<goals>
<goal>check-local-modification</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<outputDirectory>F:\deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>

Additional Links

About Adam M. Erickson

Geek, Dad, Life-Student, Biker & DIY Enthusiast Application Developer Attended Ferris State University Lives in Muskegon, MI
Bookmark the permalink.

Comments are closed.