CD part XXI: Creating a release Batch file

Johan Tuitel

  • 31/03/2017
  • 2 minuten leestijd
Johan Tuitel

CD part XXI: Creating a release Batch file

This is an extra feature we have build for automation purposes, but i would like you to show what we have done. We have defined 5 steps

create a batch file to automate creation of a release script

i have created this release-script to automating the creation of a release artifact and to create a tag in GIT.

In this release-script we do five steps to create our create-release.cmd batch file

  1. define the release version to release and the development version, which we will be using after the release has been done. We also have to define the USERSTORY in which we will be committing the release and snapshot version of the project.
    @echo off
    set /p RELEASE=Release version?
    set /p DEVELOP=Develop version?
    set /p USERSTORY=User Story number?
    echo Release %RELEASE%
    echo Development %DEVELOP%
    echo DEVNL-%USERSTORY%
    pause
  1. When we have defined our settings for the release we are going to set the new release version, check if the project builds, do the release, commit the changes into GIT.
    call mvn versions:set -DnewVersion=%RELEASE% -DgenerateBackupPoms=false
    call mvn clean install
    if "%ERRORLEVEL%"=="1" exit /b
    call mvn javadoc:jar source:jar deploy -Prelease
    if "%ERRORLEVEL%"=="1" exit /b
    call git add .
    call git commit -m "DEVNL-%USERSTORY%: created release version %RELEASE%"
    call git push
    echo create release version %RELEASE%
    pause
  1. Now we have released our artifact in nexus, we will be creating a tag in GIT by checking out the master, merge the develop-branch into the master-branch. After the merging we will be creating a release tag.
    call git checkout master
    call git merge develop
    call mvn clean install
    if "%ERRORLEVEL%"=="1" exit /b
    call git tag %RELEASE%
    call git push origin %RELEASE%
    call git checkout develop
    echo create release tag %RELEASE%
    pause
  1. Now we have a release in nexus and a release tag in GIT, we only have to set the development version in the develop-branch to continue our work for the new features.
    call mvn versions:set -DnewVersion=%DEVELOP%-SNAPSHOT -DgenerateBackupPoms=false
    call mvn clean install
    if "%ERRORLEVEL%"=="1" exit /b
    call mvn clean deploy -Prelease
    if "%ERRORLEVEL%"=="1" exit /b
    call git add .
    call git commit -m "DEVNL-%USERSTORY%: created snapshot version %DEVELOP%-SNAPSHOT"
    call git push
    echo create snapshot version %DEVELOP%-SNAPSHOT
    pause
  1. when we have put al the code in the create-release.cmd batch file, we need to put this file in the directory C:\Windows\System32, which enables us to acces this batch file from the command-prompt.

after we have done the five steps, we can call the create-release.cmd file by

    create-release.cmd 0.9 1.0 1200

note: the 0.9 is the release version, 1.0 will become the SNAPSHOT version and 1200 is the USERSTORY number.