Share This:

After running a Patching and then Remediation Job, BlPackages and Deploy Jobs are generated.  You might want to retrieve the generated Deploy Jobs for further manipulation.  This information shows up in the Remediation Job Run log:

We can use some unreleased blcli commands to get the log entries and scrape the name of the job.  There are two cases to handle - since 8.8 there is an option in Patching Global Configuration named Remediation Settings: Using Single Deploy Job.  This determines if the Remediation Job will generate a Deploy Job per generated BlPackage (< 8.8 behavior), or only a single Deploy Job that will deploy all generated BlPackages to their respective servers ( 8.8+ default behavior).  Since either case may exist in 8.8+ we need to check for both.

 

We must start with the Patching Job Run Id - this can be obtained a variety of ways that is beyond the scope of the article.  From the patching job run, we will find the remediation job run id, then pull and process the log entries from that run to get the deploy job info.

 

PATCHING_JOB="/Workspace/Patching Jobs/Windows 2016 and 2019"
typeset -a DEPLOY_JOB_KEYS
# Getting the last run of my patching job for this example:
blcli_execute PatchingJob getDBKeyByGroupAndName "${PATCHING_JOB%/*}" "${PATCHING_JOB##*/}"
blcli_storeenv PATCHING_JOB_KEY
blcli_execute JobRun findLastRunKeyByJobKey ${PATCHING_JOB_KEY}
blcli_storeenv PATCHING_JOB_RUN_KEY
blcli_execute JobRun jobRunKeyToJobRunId ${PATCHING_JOB_RUN_KEY}
blcli_storeenv PATCHING_JOB_RUN_ID
# get the patching job run child ids (one will be the remediation job id)
blcli_execute JobRun findPatchingJobChildrenJobsByRunKey ${PATCHING_JOB_RUN_ID}
blcli_execute JobRun getJobRunId
blcli_execute Utility setTargetObject
blcli_execute Utility listPrint
blcli_storeenv PATCH_ANALYSIS_JOB_RUN_IDS
for JOB_RUN_ID in ${PATCH_ANALYSIS_JOB_RUN_IDS}
        do
        blcli_execute JobRun findById ${JOB_RUN_ID}
        blcli_execute JobRun getType
        blcli_storeenv JOB_RUN_TYPE_ID
        if [[ ${JOB_RUN_TYPE_ID} = 7033 ]]
                then
                break
        fi
done
# get the log entries for the remediation job
blcli_execute JobRun findById ${JOB_RUN_ID}
blcli_execute JobRun getJobKey
blcli_storeenv REMEDIATION_JOB_KEY
blcli_execute LogItem getLogItemsByJobRun ${REMEDIATION_JOB_KEY} ${JOB_RUN_ID}
blcli_execute Utility storeTargetObject logItems
blcli_execute Utility listLength
blcli_storeenv LIST_LENGTH
if [[ ${LIST_LENGTH} -gt 0 ]]
        then
        for i in {0..$((${LIST_LENGTH}-1))}
                do
                blcli_execute Utility setTargetObject logItems
                blcli_execute Utility listItemSelect ${i}
                blcli_execute Utility setTargetObject
                blcli_execute JobLogItem getMessage
                blcli_storeenv MESSAGE
                 # look for the < 8.8 case:
                if ( grep -q "Created deploy job" <<< "${MESSAGE}" )
                        then
                        DEPLOY_JOB_NAME="$(grep "Created deploy job" <<< "${MESSAGE}" | cut -f2- -d: | sed "s/^ Jobs//")"
                        echo "DEPLOY_JOB_NAME: ${DEPLOY_JOB_NAME}"
                        blcli_execute DeployJob getDBKeyByGroupAndName "${DEPLOY_JOB_NAME%/*}" "${DEPLOY_JOB_NAME##*/}"
                        blcli_storeenv DEPLOY_JOB_KEY
                        DEPLOY_JOB_KEYS+=${DEPLOY_JOB_KEY}
                fi
                 # look for the 8.8+ case
                if ( grep -q "Created Batch Job" <<< "${MESSAGE}" )
                        then
                        BATCH_JOB_NAME="$(grep "Created Batch Job" <<< "${MESSAGE}" | cut -f2- -d: | sed "s/^ Jobs//")"
                        echo "BATCH_JOB_NAME: ${BATCH_JOB_NAME}"
                        blcli_execute BatchJob getDBKeyByGroupAndName "${BATCH_JOB_NAME%/*}" "${BATCH_JOB_NAME##*/}"
                        blcli_storeenv batchJobKey
                        blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey ${batchJobKey}
                        blcli_execute SJobHeader getDBKey
                        blcli_execute Utility setTargetObject
                        blcli_execute Utility listPrint
                        blcli_storeenv batchMembers
                        batchMembers="$(awk 'NF' <<< "${batchMembers}")"
                        while read i
                                do
                                blcli_execute Job findByDBKey ${i}
                                blcli_execute Job getName
                                blcli_storeenv deployJobName
                                blcli_execute Job getGroupId
                                blcli_storeenv deployJobGroupId
                                blcli_execute Group getQualifiedGroupName 5005 ${deployJobGroupId}
                                blcli_storeenv deployGroupPath
                                blcli_execute DeployJob getDBKeyByGroupAndName "${deployGroupPath}" "${deployJobName}"
                                blcli_storeenv jobKey
                                if [[ "${DEPLOY_JOB_KEYS/${jobKey}}" = "${DEPLOY_JOB_KEYS}" ]]
                                        then
                                        echo "DEPLOY_JOB: ${deployGroupPath}/${deployJobName}"
                                        echo "DEPLOY_JOB_KEY: ${jobKey}"
                                        DEPLOY_JOB_KEYS+="${jobKey}"
                                fi
                         done <<< "${batchMembers}"
                fi
        done
else
        echo "Could not find job logs for ${REMEDIATION_JOB_KEY}..."
        exit 1
fi

 

This will generate output like:

Single Job Mode:

BATCH_JOB_NAME: /Workspace/Patching Jobs/Deploy/Windows 2016 and 2019 batch deploy Windows 2016 and 2019@2019-09-29 14-41-25-125-0400
DEPLOY_JOB: /Workspace/Patching Jobs/Deploy/Windows 2016 and 2019-20011681 @ 2019-09-29 14-41-24-319-0400
DEPLOY_JOB_KEY: DBKey:SJobModelKeyImpl:2001176-1-2131104
DBKey:SJobModelKeyImpl:2001176-1-2131104

 

Multiple Deploy Jobs:

DEPLOY_JOB_NAME: /Workspace/Patching Jobs/Deploy/Windows 2016 and 2019-win16-894p2.example.com-20011681 @ 2019-09-29 14-51-40-404-0400
DEPLOY_JOB_NAME: /Workspace/Patching Jobs/Deploy/Windows 2016 and 2019-win19-894p2.example.com-20011681 @ 2019-09-29 14-51-42-179-0400
BATCH_JOB_NAME: /Workspace/Patching Jobs/Deploy/Windows 2016 and 2019 batch deploy Windows 2016 and 2019@2019-09-29 14-51-42-726-0400
DBKey:SJobModelKeyImpl:2001183-1-2131308 DBKey:SJobModelKeyImpl:2001189-1-2131320

 

Once you have the name and DBKey of the generated Deploy Job, you can then proceed to do whatever you need to do to/for/with these jobs.