Jenkins/Hudson

When a new application version is built and tested, the application archive is passed to LiveRebel for a release, or a new deployment. Jenkins communicates with LiveRebel by using the LiveRebel CLI. In this guide we’ve outlined the set up process and ready-made CLI scripts for common use cases to make the integration quick and easy. Follow the instructions and consult the CLI reference for a full list of commands and options.

Prerequisites

The integration uses CLI to communicate with LiveRebel. Follow the instructions in the CLI guide to make sure that CLI is available and configured properly on the Jenkins machine.

Adding LiveRebel to a Job

Choose the job you want to add LiveRebel as a build step and click Configure:

../_images/jenkins-configure.png

Scroll to the Build section and click Add build step:

../_images/jenkins-build-step.png

Choose Execute shell if you’re on Unix, or Execute Windows batch command on Windows. Copy and modify one of the CLI scripts listed in this guide:

../_images/jenkins-command.png

Using in an Production Environment

In a production environment, the initial deployments is set up once in LiveRebel and new versions released on top of it. Usually every built archive is uploaded to LiveRebel and when one is deemed worthy of a release, released from LiveRebel UI. In a true continuous deployment process, you’d want to initiate both uploading the archive and releasing it from Jenkins.

Uploading an Archive

On Unix
# Set parameters
APPLICATION_ID="lr-demo-answers-java"
APPLICATION_VERSION="build-$BUILD_NUMBER"
APPLICATION_ARCHIVE="lr-demo-answers-java.war"

# Upload archive to LiveRebel
lr-cli.sh upload -file "$APPLICATION_ARCHIVE" -app "$APPLICATION_ID" -ver "$APPLICATION_VERSION"
On Windows
REM Set parameters
APPLICATION_ID=lr-demo-answers-java
APPLICATION_VERSION=build-%BUILD_NUMBER%
APPLICATION_ARCHIVE=lr-demo-answers-java.war

REM Upload archive to LiveRebel
call lr-cli upload -file "%APPLICATION_ARCHIVE%" -app "%APPLICATION_ID%" -ver "%APPLICATION_VERSION%"

Releasing an Application

On Unix
# Set parameters
DEPLOYMENT_NAME="Answers Production"
APPLICATION_ID="lr-demo-answers-java"
APPLICATION_VERSION="build-$BUILD_NUMBER"
RELEASE_MODE="ROLLING"
SESSION_DRAIN_TIMEOUT="30"

# Generate descriptor
DESCRIPTOR=$(printf "[
  {
    'app':'%s',
    'ver':'%s',
    'updateMode':{
        'name':'%s',
        'timeout':'%s'
    }
  }
]" "$APPLICATION_ID" "$APPLICATION_VERSION" "$RELEASE_MODE" "$SESSION_DRAIN_TIMEOUT")

# Release application
echo $DESCRIPTOR | lr-cli.sh release-deployment -name "$DEPLOYMENT_NAME" -log-file liverebel.log -apps -

# Print log to Console
cat liverebel.log
On Windows
REM Set parameters
set DEPLOYMENT_NAME=Answers Production
set APPLICATION_ID=lr-demo-answers-java
set APPLICATION_VERSION=build-%BUILD_NUMBER%
set RELEASE_MODE=ROLLING
set SESSION_DRAIN_TIMEOUT=30

REM Generate descriptor
set DESCRIPTOR=^
[                                            ^
  {                                          ^
    'app':'%APPLICATION_ID%',                ^
    'ver':'%APPLICATION_VERSION%',           ^
    'updateMode':{                           ^
        'name':'%RELEASE_MODE%',             ^
        'timeout':'%SESSION_DRAIN_TIMEOUT%'  ^
    }                                        ^
  }                                          ^
]

REM Create the deployment
echo %DESCRIPTOR% | lr-cli release-deployment -name "%DEPLOYMENT_NAME%" -log-file liverebel.log -apps -

REM Print log to Console
type liverebel.log

Using in a QA Environment

In a QA environment, when a version is built and ready for testing, generally a fresh environment is set up. When the testing process has finished, the environment is completely teared down.

Creating a New Deployment

On Unix
# Set parameters
DEPLOYMENT_NAME="Answers Test Build #$BUILD_NUMBER"
APPLICATION_ARCHIVE="lr-demo-answers-java.war"
APPLICATION_ID="lr-demo-answers-java"
APPLICATION_VERSION="build-$BUILD_NUMBER"
SERVER_GROUP="Answers-Java"
DATABASE_SERVER="MySQL"
DATABASE_SCHEMA="answers_java"
CONTEXT_PATH="/lr-demo-answers-java"

# Upload archive to LiveRebel
lr-cli.sh upload -file "$APPLICATION_ARCHIVE" -app "$APPLICATION_ID" -ver "$APPLICATION_VERSION"

# Generate descriptor
DESCRIPTOR=$(printf "[
  {
    'app':'%s',
    'ver':'%s',
    'contextPath':'%s',
    'groupNames':['%s'],
    'database':{
        'server':'%s',
        'schema':'%s'
     }
  }
]" "$APPLICATION_ID" "$APPLICATION_VERSION" "$CONTEXT_PATH" "$SERVER_GROUP" "$DATABASE_SERVER" "$DATABASE_SCHEMA")

# Create the deployment
echo "$DESCRIPTOR" | lr-cli.sh create-deployment -name "$DEPLOYMENT_NAME" -log-file liverebel.log -apps -

# Print log to Console
cat liverebel.log
On Windows
REM Set parameters
set DEPLOYMENT_NAME=Answers Test Build #%BUILD_NUMBER%
set APPLICATION_ARCHIVE=lr-demo-answers-java.war
set APPLICATION_ID=lr-demo-answers-java
set APPLICATION_VERSION=build-%BUILD_NUMBER%
set SERVER_GROUP=Answers-Java
set DATABASE_SERVER=MySQL
set DATABASE_SCHEMA=answers_java
set CONTEXT_PATH=/lr-demo-answers-java

REM Upload archive to LiveRebel
call lr-cli upload -file "%APPLICATION_ARCHIVE%" -app "%APPLICATION_ID%" -ver "%APPLICATION_VERSION%"

REM Generate descriptor
set DESCRIPTOR=^
[                                            ^
  {                                          ^
    'app':'%APPLICATION_ID%',                ^
    'ver':'%APPLICATION_VERSION%',           ^
    'contextPath':'%CONTEXT_PATH%',          ^
    'groupNames':['%SERVER_GROUP%'],         ^
    'database':{                             ^
        'server':'%DATABASE_SERVER%',        ^
        'schema':'%DATABASE_SCHEMA%'         ^
     }                                       ^
  }                                          ^
]

REM Create the deployment
echo %DESCRIPTOR% | lr-cli create-deployment -name "%DEPLOYMENT_NAME%" -log-file liverebel.log -apps -

REM Print log to Console
type liverebel.log

Removing a Deployment

On Unix
# Set parameters
DEPLOYMENT_NAME="Answers Production"

# Remove deployment
lr-cli.sh delete-deployment -name "$DEPLOYMENT_NAME" -log-file liverebel.log

# Print log to Console
cat liverebel.log
On Windows
REM Set parameters
set DEPLOYMENT_NAME=Answers Production

REM Remove deployment
call lr-cli delete-deployment -name "%DEPLOYMENT_NAME%" -log-file liverebel.log

REM Print log to Console
type liverebel.log

Application Name and Version from Archive

The scripts listed above set the application id and version parameters themselves. If your build process already generates a proper liverebel.xml, you can set these parameters automatically with CLI name and version commands.

On Unix
# Set parameters
APPLICATION_ARCHIVE="lr-demo-answers-java.war"
APPLICATION_ID=`lr-cli.sh name -file "$APPLICATION_ARCHIVE"`
APPLICATION_VERSION=`lr-cli.sh version -file "$APPLICATION_ARCHIVE"`
On Windows
REM Set parameters
APPLICATION_ARCHIVE=lr-demo-answers-java.war
for /f "delims=" %%i in ('lr-cli name -file %APPLICATION_ARCHIVE%') do set APPLICATION_ID=%%i
for /f "delims=" %%i in ('lr-cli version -file %APPLICATION_ARCHIVE% ') do set APPLICATION_VERSION=%%i