Walkthrough: Auto-packaging process of directory files
Article written: Feb 2013
BL version compatibility: 8.2
Platform used in example: Win 2008 App server, SQL2008R2 (DB), target machine is redhat 5.3
Section A - Background
Some customers use 3rd party applications to create deployment files for their environment, and then use Blade to package these files, and use Blade to deploy these files all over their environment. Recently a customer had a request for a Blade script in order to automatically package files generated by their Jenkins application - into Blade, as BLPackages. Once these files were packaged as BLPackages, they would deploy these files to their environment using Blade. Instead of manually adding each file and creating BLPackages manually, they wanted to automate the process by running a NSH script from command line.
In this scenario, a user is logged into a Redhat box (Payload server) that contains Jenkins build files, he then starts an NSH session (make sure Blade Console is installed on this Redhat box - so that the script can use 'blcred' utility). The user kicks off a NSH script that generates a feed file. The script then kicks off 2 other NSH scripts (running on Blade app server) that read the feed file and create a BLPackage based on the contents of the feed file. The scripts then create deploy and uninstall jobs. See the diagram below for further explanation.
Section B -Setting up the environment
- Place the ‘run_pkg.nsh’ on the Jenkins (Payload) box - or the server where you host your build files.
- Make sure to install the Bladelogic console on this server, you will need the blcred utility for this process, and it only comes with the Console install
- Upload ‘create_depot_path.nsh’ and ‘make_pkg.nsh’ to Blade, create Parameters on each script in Blade
for create_depot_path.nsh – create 1 parameter called PATH, editable=yes
for make_pkg.nsh – create 4 parameters
- Update create_depot_path.nsh with Blade path to the Jenkins package folders, these folders need to be created in Depot, Component Templates and Jobs areas, make sure all folders match up with names.
Depot > Deployment > Jenkins > packages (Update the variable $JENKINS_PATH)Component Templates > Deployment > Jenkins > packages
Jobs > Deployment > Jenkins > packages
- Create NSH Script Jobs in Blade (one for MakePkg and one for CreateDepotPath)
- On Jenkins, open run_pkg.nsh and update variables
update $CENTRAL_DIR – this is the location where the script will place feed files, as well as the lock file
update $PKGPROCESS_JOB_FOLDER to reference your deployment path (in Blade Depot)
update $COPY_JOB_NAME, $PKG_JOB_NAME, $CREATE_DEPOT_JOB_NAME to reference your Blade jobs
update $SRC to reference your Jenkins box hostname (make sure this box is managed by Blade and Blade can deploy jobs to it)
- Execute the script like this
$> ./run_pkg.nsh myProfile myUserName myPasswd /opt/jenkins /www/install pkg120 target
myProfile = blcred profile
myUserName = Bladelogic account that will be used to run this NSH script
myPasswd = password for this account
/opt/jenkins = path to your Jenkins-generated packages (this is a stage directory of your choice)
/www/install = install directory on the target server - your choice, (files will be moved from the stage directory to here)
pkg120 = folder name that will be created in Blade depot to store these BLPackage (change this to your choice)
target = hostname of the target where these files will be deployed to
The script will create a lock file (to prevent other users from running the same script concurrently) and start updating Blade Job parameters, generating unique feed files (based on Datetime stamp), executing jobs in blade to create Depot folder and create BLPackages. The script that creates the Depot folders in Blade is create_depot_path.nsh
- The make_pkg.nsh script then creates Component Templates in these Depot directories. These Component Templates contain the build files from the feed file.
It then builds a BLPackage that includes all those files, including a Pre and Post command (make sure to include 2 files in same feed directory, call these 2 files PreCmd and PostCmd. The script looks for these 2 files and adds them to this BLPackage. It also adds a Move command to move everything from stage to install directory). The Move command is generated automatically by the script
- The make_pkg.nsh then creates a Discovery Job that goes out to the Jenkins box and discovers all those files. It also creates a Deploy and Uninstall job
- The user then logs into Bladelogic, executes the BLPackage deploy job, which will deploy these files to the target server, then moves them over to the designated install directory.