Share This:

As part of automating your patch deployments you may want to run your Patching Job and have it automatically generate the BlPackages and Deploy Jobs that contain missing patches and go ahead and schedule the various phases of the generated Deploy Jobs.  This is fairly simple in the gui.  In a Patching Job, on the Remediation Options tab, click on the Deploy Job Options button and then goto the Phases and Schedules tab.

2019-07-17_16-19.png

While this is trivial for a single job, if you have several jobs to modify every patching cycle this becomes quite tedious.  We will of course turn to our friend the BLCLI.  There's a hint in the screenshot above as to how we will accomplish this.  The Populate options from an existing Job looks interesting.  And in-fact if I create a 'dummy' Deploy Job, setup the options and schedule that I want and then select that in the Populate options from an existing Job menu, the schedule and options are applied to my Patching Job / Deploy Job Options.

 

To really automate this I need to do a few things: Figure out the options and schedule we want set in the Patching Job, create or update a 'dummy' deploy job with the options and schedule I want, find my Patching Job (we could create one from scratch but not for this exercise), apply the 'dummy' job to the Patching Job, remove the schedule from the dummy job, and then optionally execute or schedule the Patching Job.

 

Dummy Job

To create the 'dummy job' we need a blpackage.  Let's provide the name and path to a BlPackage and create an empty BlPackage if it does not exist.

DUMMY_BLPACKAGE="/Workspace/TestDeploy"
blcli_execute DepotGroup groupNameToDBKey "${DUMMY_BLPACKAGE%/*}"
blcli_storeenv depotGroupKey
blcli_execute DepotObject depotObjectExistsByTypeGroupAndName 28 ${depotGroupKey} "${DUMMY_BLPACKAGE##*/}"
blcli_storeenv pkgExists
if [[ "${pkgExists}" = "true" ]]
    then
    blcli_execute BlPackage getDBKeyByGroupAndName "${DUMMY_BLPACKAGE%/*}" "${DUMMY_BLPACKAGE##*/}"
else
    blcli_execute DepotGroup groupNameToId "${DUMMY_BLPACKAGE%/*}"
    blcli_storeenv depotGroupId
    blcli_execute BlPackage createEmptyPackage "${DUMMY_BLPACKAGE##*/}" "" ${depotGroupId}
    blcli_execute DepotObject getDBKey
fi
blcli_storeenv PACKAGE_KEY
echo "PACKAGE_KEY:${PACKAGE_KEY}"

Now that we have our dummy BlPackage, let's do the same with the dummy job.  When we create the deploy job, we'll pass parameters as defined in the DeployJob - createDeployJob_3 - Documentation for BMC Server Automation Command Line Interface 8.9 - BMC Documentation command.

 

DEPLOY_OPTS="${BASIC_DEPLOY_OPTS} ${ADVANCED_OPTS}"
DUMMY_BLDEPLOY="/Workspace/TestDeploy"
DUMMY_TARGET_SERVER="server1"
blcli_execute JobGroup groupNameToDBKey "${DUMMY_BLDEPLOY%/*}"
blcli_storeenv jobGroupKey
blcli_execute Job jobExistsByTypeGroupAndName 30 ${jobGroupKey} "${DUMMY_BLDEPLOY##*/}"
blcli_storeenv jobExists
if [[ "${jobExists}" = "true" ]]
    then
    blcli_execute DeployJob getDBKeyByGroupAndName "${DUMMY_BLDEPLOY%/*}" "${DUMMY_BLDEPLOY##*/}"
else
    blcli_execute JobGroup groupNameToId "${DUMMY_BLDEPLOY%/*}"
    blcli_storeenv GROUP_ID
    blcli_execute DeployJob createDeployJob "${DUMMY_BLDEPLOY##*/}" "${GROUP_ID}" "${PACKAGE_KEY}" "${DEPLOY_TYPE}" "${DUMMY_TARGET_SERVER}" ${DEPLOY_OPTS}
fi
blcli_storeenv DEPLOY_JOB_KEY
echo "DEPLOY_JOB_KEY:${DEPLOY_JOB_KEY}"

 

Now we can set the phase schedules on the dummy job:

blcli_execute DeployJob setAdvanceDeployJobPhaseScheduleByDBKey ${DEPLOY_JOB_KEY} AtTime "${SIMULATE_TIME}" "${STAGE_DATE_TIME}" "" AtTime "${COMMIT_TIME}"
blcli_storeenv DEPLOY_JOB_KEY
echo "DEPLOY_JOB_KEY:${DEPLOY_JOB_KEY}"

 

Patching Job

Apply the options and schedule from the dummy job on your patching job:

 

PATCH_JOB="/Workspace/Patching Jobs/rhel6-clean"
REMEDIATION_DEPOT_FOLDER="/Workspace/Patch Deploy"
REMEDIATION_JOB_FOLDER="/Workspace/Patching Jobs"
REMEDIATION_JOB_PREFIX="${PATCH_JOB##*/}-"
blcli_execute PatchingJob setRemediationWithDeployOptions ${PATCH_JOB_KEY} "${REMEDIATION_JOB_PREFIX}" "${REMEDIATION_DEPOT_FOLDER}" "${REMEDIATION_JOB_FOLDER}" ${DEPLOY_JOB_KEY}
blcli_storeenv PATCH_JOB_KEY
echo "PATCH_JOB_KEY:${PATCH_JOB_KEY}"

 

 

Optionally schedule the Patching Job

blcli_execute Job addOneTimeSchedule ${PATCH_JOB_KEY} "${ANALYSIS_TIME}"
blcli_storeenv PATCH_JOB_KEY
echo "PATCH_JOB_KEY:${PATCH_JOB_KEY}"

 

 

And that's it.  The attached script includes a hard-coded start time for the Deploy phases and Patching Job.  Those could be taken as input to the script or derived somehow.  There's also a check to see if the executeDeployJobsNow option is set and exit out since this requires manual correction.

 

There are a few things that could be done in the script that are not covered and left an an exercise for the reader:

  • Delete the dummy job and package after they've been used
  • Set pre- and post- commands in the Deploy Job options
  • Take the various options, schedule times, job path, folders, etc as script arguments