Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Monday, 8 February 2016

jgit-flow maven plugin to Release Java Application

Introduction

As a DevOps I need a smooth way to release the java application, so I compared two maven plugin that are used to release the java application and in the end I found that Jgit-flow plugin is far better than maven-release plugin on the basis of following points:
  • Maven-release plugin creates .backup and release.properties files to your working directory which can be committed mistakenly, when they should not be. jgit-flow maven plugin doesn't create these files or any other file in your working directory.
  • Maven-release plugin create two tags.
  • Maven-release plugin does a build in the prepare goal and a build in the perform goal causing tests to run 2 times but jgit-flow maven plugin builds project once so tests run only once.
  • If something goes wrong during the maven plugin execution, It become very tough to roll it back, on the other hand jgit-flow maven plugin makes all changes into the branch and if you want to roll back just delete that branch.
  • jgit-flow maven plugin doesn't run site-deploy
  • jgit-flow maven plugin provides option to turn on/off maven deployment
  • jgit-flow maven plugin provides option to turn on/off remote pushes/tagging
  • jgit-flow maven plugin keeps the master branch always at latest release version.
Now let's see how to integrate Jgit-flow maven plugin and use it

    How to use Jgit-flow maven Plugin for Release

    Follow the flowing steps 
    1. Add the following lines in your pom.xml for source code management access
             
      <scm>
        <connection>scm:git:<Git Repo URL></connection>
        <developerConnection>scm:git:git:<Git Repo URL></developerConnection>
      </scm>

    2. Add these line to resolve the Jgit-flow maven plugin and put the other option that will be required during the build
             
      <build>
          <plugins>
            <plugin>
              <groupId>com.atlassian.maven.plugins</groupId>
              <artifactId>maven-jgitflow-plugin</artifactId>
              <version>1.0-m4.3</version>
              <configuration>
                <pushReleases>true</pushReleases>
               <keepBranch>false</keepBranch>
      <autoVersionSubmodules>true</autoVersionSubmodules>
                <noTag>true</noTag>
                <allowUntracked>true</allowUntracked>
      <pullDevelop>true</pullDevelop>
      <pullMaster>true</pullMaster>
      <allowSnapshots>true</allowSnapshots>
                <flowInitContext>
                  <masterBranchName>master-test</masterBranchName>
                  <developBranchName>deploy-test</developBranchName>
                </flowInitContext>
              </configuration>
           </plugin>
        </plugins>
      </build>
       
    3. Above code snippet will perform following steps:
      • Maven will resolve the jgitflow plug-in dependency
      • In the configuration section, we describe how jgit-flow plug-in will behave.
      • pushRelease XML tag to enable and disable jgit-flow from releasing the intermediate branches into the git or not.
      • keepBranch XML tag to enable and disable the plug-in for keep the intermediate branch or not.
      • noTag XMl tag to enable and disable the plug-in to create the that tag in git.
      • allowUntracked XML tag to whether allow untracked file during the checking. 
      • flowInitContext XML tag is used to override the default and branch name of the jgit-flow plug-in
      • In above code snippet, there is only two branches, master from where that code will be pulled and a intermediate branch that will be used by the jgit-flow plug-in. as I have discussed that jgit-flow plug-in uses the branches to keep it records. so development branch will be created by the plug-in that resides in the local not remotely, to track the release version etc. 
    4. To put your your releases into the repository manager add these lines
             
      <distributionManagement>
        <repository>
          <id><auth id></id>
          <url><repo url of repository managers></url>
        </repository>
        <snapshotRepository>
          <id><auth id></id>
          <url><repo url of repository managers></url>
        </snapshotRepository>
      </distributionManagement>

    5. Put the following lines into your m2/settings.xml with your repository manager credentials
              
      <settings>
        <servers>
          <server>
              <id><PUT THE ID OF THE REPOSITORY OR SNAPSHOTS ID HERE></id>
            <username><USERNAME></username>
            <password><PASSWORD></password>
          </server>
        </servers>
      </settings>

    Start Release jgit-flow maven plugin command

    To start the new release execute jgitflow:release-start.  

    Finish Release jgit-flow maven plugin  command

    To finish new release, execute mvn jgitflow:release-finish.

    For a example I have created a repository in github.com. for testing and two branch master-test and deploy-test. It is assumed that you have configured maven and git your system.
    In the deploy-test branch run following command
    $ mvn clean -Dmaven.test.skip=true install jgitflow:release-start


    This command will take input from you for release version and create a release branch with release/<version>. then it will push this release branch into github repository for temporarily because we are not saving the intermediate branched





















    Now At the end run this command
    $ mvn -Dmaven.test.skip=true jgitflow:release-finish
    after finishing this command it will delete release/<version> from local and remote.











    Now you can check the changes in pom file by jgitflow. in the above snapshot, it is master-test branch, you can see in the <version> tag it has removed the snapshot and also increased the version.  It hold the current version of the application.

    And in the deploy-test branch it show you new branch on which developers are working on









    Monday, 4 March 2013

    Automation tips and tricks February 2013

    As promised I'm back with the summary of cool stuff that I've done with my team in Build & Release domain to help us deal with day to day problems in efficient & effective way. As I said this month was about creating tools/utilities that sounds very simple but overall their impact in productivity & agility of build release teams and tech verticals was awesome :).

    Automated deployment of Artifacts : If you have ever worked with a set of maven based projects that are interdependent on each other, one of the major problem that you will face in such a setup is to have the latest dependencies in your local system. Here I'm assuming two things you would be using a Maven Repo to host the artifacts & the dependencies would be SNAPSHOT dependencies if their is active development going on dependencies as well. Now the manual way of making sure that maven repo will always have the latest SNAPSHOT version is that every-time somebody does change in the code-base he/she manually deploy that artifact to maven repo. What we have done is that for each & every project we have created a Jenkins job that check if code is checked in for a specific component & if so that component's SNAPSHOT version get's deployed to maven repo. The impact of these utilities jobs was huge as now all the developers doesn't have to focus on deploying their code to maven repo & also keeping track of who last committed the code was also not needed.

    Log Parser Utility : We have done further improvement in our event based log analyzer utility. Now we also have a simple log parser utility through which we can parse the logs of a specific component & segregate the logs as per ERROR/WARN/INFO. Most importantly it is integrated with jenkins so you can go to jenkins select a component whose log needs to be analyzed, once analysis is finished the logs are segregated as per our configuration(in our case it is ERROR/WARN/INFO) after that in the left bar these segregations are shown with all the various instances of these categories and user can click on those links to go exactly at the location where that information is present in logs

    Auto Code Merge : As I already told we have a team of around 100+ developers & a sprint cycle of 10 days and two sprints overlap each other for 5 days i.e first 5 days for development after tat code freeze is enforced and next 5 days are for bug fixing which means that at a particular point of time there are 3 parallel branches on which work is under progress one branch which is currently deployed in production second branch on which testing is happening and third branch on which active development is happening. You can easily imagine that merging these branches is a task in itself. What we have done is to create an automated code merge utility that tries to merge branches in a per-defined sequence if automatic merge is successful the merge proceeds for next set of branches otherwise a mail is sent to respective developers whose files are in conflict mode

    Hope you will get motivated by these set of utilities & come up with new suggestions or point of improvements