Continuous Delivery
David Farley about Continuous Delivery Petra Kiers 24 Feb, 2014
<version>${release}-${revision}</version> <parent><version>1.0-SNAPSHOT</version></parent>The parent POM is a convenient place to define appropriate default values for the release and revision properties:
<version>1.0-SNAPSHOT</version> <properties><release>1.0</release><revision>SNAPSHOT</revision></properties>Now, in order to have the actual revision number correctly included into the project version of each module, it needs to be passed as system property -Drevision=$N to the Maven build process. Note that the Build Number Maven Plugin cannot be used to take care of that as it can set the revision number only after the project versions have already been resolved by Maven. Supposing that Jenkins is used as build server and Subversion is used as version control system, N can simply be replaced by the Jenkins built-in variable SVN_REVISION. In case of downstream builds within a true pipeline N must be replaced by the special pipeline variable PL_SVN_REVISION. The project can still be built without passing a revision number as system property, in which case the modules will simply have the same snapshot version as the parent project. This is sufficient for local developer builds. Having the top-level Maven project configured with dynamic project versions, it is no longer possible to make use of the Maven Release Plugin as this plugin would simply replace all expressions by static versions. Obviously, the same applies to the Jenkins M2Release Plugin. But there is no longer a need to perform a Maven release anyway as we are implementing the concept of continuous releasing. This means in particular that there are no longer revisions automatically tagged within the version control system. This makes sense as every revision already identifies an unique version and is a candidate for deployment to a production environment. Furthermore, there are no longer artifact versions deployed to a Maven repository manager like Nexus. However, Jenkins itself can be used as a Maven repository server. The Jenkins Maven Repository Server Plugin exposes all archived artifacts in one single repository as long as they have been created for different revision numbers:
${JENKINS_URL}plugin/repository/everything/Another key benefit of creating release versions only is that continuous integration and continuous deployment have become an even closer match. With the Deployit Plugin it is very easy to generate, import and deploy deployment packages. Such deployment packages will have the same unique application version as the generated deployables that are contained within these packages. Apart from the parent POM version there are no snapshot versions involved, so there is no need to use other identifiers such as timestamps in order to identify deployed applications. Although a Maven release is no longer performed, there will still be a need to update the static major release number from time to time in order to reflect certain application changes. This can simply be accomplished by one single manual commit. The parent POM and child POMs can be updated to a new release number with ease by using the Versions Maven Plugin:
mvn versions:set -DgenerateBackupPoms=falseThe release property in the parent POM also needs to be updated accordingly. When a Maven release is prepared it is automatically verified that the revision to be released does not have any snapshot dependencies. Now that every revision is considered to be a release, this rule actually applies to every revision. In order to have this automatically checked the Maven Enforcer Plugin can be used to enforce the applicable rule Require Release Dependencies. As the parent POM will have a snapshot version at all times the property failWhenParentIsSnapshot needs to be set to false though. This check is typically only performed on the build server, naturally through Maven profile activation.