3 Replies Latest reply on Jan 27, 2014 2:03 PM by Bill Robinson

    Can I create Folders under Job using BLCli

    Rajeev Gupta

      While I am creating and deploying multiple deploy jobs based on some conditions, all the jobs are currently going under a particular folder structure (which already exists) as given in the NSH Script.

       

      JOB_FOLDER="/$LOB/$APP_NAME"

      blcli_execute JobGroup groupNameToId "${JOB_FOLDER}" > /dev/null && blcli_storeenv GROUP_ID

       

      if [ $SOFTWARE_TYPE = "CUSTOM_SOFTWARE_INSTALLABLE" ]; then

      blcli_execute DeployJob createSoftwareDeployJob "${DEPLOY_JOB_NAME}" $GROUP_ID $SOFTWARE_KEY $SOFTWARE_TYPE $TARGET_SERVER $DEPLOY_OPTS > /dev/null && blcli_storeenv DEPLOY_JOB_KEY

      else

        blcli_execute DeployJob createDeployJob "${SHORT_DEPLOY_JOB_NAME}" $GROUP_ID $SOFTWARE_KEY $DEPLOY_TYPE $TARGET_SERVER $DEPLOY_OPTS > /dev/null && blcli_storeenv DEPLOY_JOB_KEY

        echo "Debug: ${DEPLOY_JOB_KEY}"

       

      Now, if I want to create a folder structure as per my conditions, can I create a new folder everytime using the command line only?

      What would be command for that ?

      PS : when i use the JOB_FOLDER="/$LOB/$APP_NAME", this works since this is already in the console. But, when i try using JOB_FOLDER="/$LOB/$APP_NAME/Conditions", this doesnt work as there is no folder inside APP_NAME

        • 1. Re: Can I create Folders under Job using BLCli
          Bill Robinson

          you have to make sure each group along the path is present.  there's nothing like a mkdir -p in blcli but i wrote a function that does this:

          you have to make sure each group along the path is present.  there's nothing like a mkdir -p in blcli but i wrote a function that does this:

           

          createGroup()

           

          {

           

              print_debug2 "Entering function: ${0}..."   

           

              local groupTypeString="${1}" && print_variable "groupTypeString"

           

              local fullGroupName="${2}" && print_variable "fullGroupName"

           

              local parentGroupTypeString="${3}" && print_variable "parentGroupTypeString"

           

              local matchAll="${4}" && print_variable "matchAll"

           

              local sgConditions="${5}" && print_variable "sgConditions" 

           

              local conditions

           

              conditions=("${(s/|/)sgConditions}")

           

              local parentGroupName="${2%/*}" && print_variable "parentGroupName"

           

              local groupName="${2##*/}" && print_variable "groupName"

           

             

           

              blcli_execute Utility convertModelType "${groupTypeString}"

           

              blcli_storeenv groupTypeId

           

              blcli_execute Utility convertModelType "${parentGroupTypeString}"

           

              blcli_storeenv parentGroupTypeId

           

              blcli_execute Group groupExistsByTypeAndName ${groupTypeId} "${fullGroupName}"

           

              blcli_storeenv groupExists

           

              if [[ "${groupExists}" = "false" ]]

           

                  then

           

                  local parentGroupPath=""

           

                  while read groupName

           

                      do

           

                      if [[ "${fullGroupName}" != "${parentGroupPath}/${groupName}" ]]

           

                          then

           

                          blcli_execute Group groupExistsByTypeAndName ${parentGroupTypeId} "${parentGroupPath}/${groupName}"

           

                          blcli_storeenv groupPathExists

           

                          if [[ "${groupPathExists}" = "false" ]]

           

                              then

           

                              blcli_execute Group createGroupWithParentName "${${(C)${parentGroupTypeString}//_/ }// /}" ${parentGroupTypeId} "${groupName}" "${parentGroupPath:=/}"

           

                              blcli_storeenv groupId

           

                          fi

           

                      else

           

                          blcli_execute Group groupExistsByTypeAndName ${groupTypeId} "${parentGroupPath}/${groupName}"

           

                          blcli_storeenv groupPathExists

           

                          if [[ "${groupPathExists}" = "false" ]]

           

                              then

           

                              if [[ "${groupTypeString/SMART}" = "${groupTypeString}" ]]

           

                                  then

           

                                  blcli_execute Group createGroupWithParentName "${${(C)${groupTypeString:r}//_/ }// /}" ${parentGroupTypeId} "${groupName}" "${parentGroupPath:=/}"

           

                                  blcli_storeenv groupId

           

                              else

           

                                  for i in {1..${#conditions}}

           

                                      do

           

                                      local condition

           

                                      condition=("${(s/,/)conditions[${i}]}")

           

                                      if [[ ${i} -eq 1 ]]

           

                                          then

           

                                          if [[ "${groupTypeString/SERVER}" != "${groupTypeString}" ]]

           

                                              then

           

                                              blcli_execute "${${(C)${groupTypeString:r}//_/ }// /}" createGroup "${fullGroupName%/*}" "${groupName}" "${groupName}" "${condition[2]}" "${condition[3]}" "${condition[4]}"

           

                                          else

           

                                              blcli_execute "${${(C)${groupTypeString:r}//_/ }// /}" createGroup "${fullGroupName%/*}" "${groupName}" "${groupName}" "${condition[1]}" "${condition[2]}" "${condition[3]}" "${condition[4]}"

           

                                          fi

           

                                      else

           

                                          if [[ "${groupTypeString/SERVER}" != "${groupTypeString}" ]]

           

                                              then

           

                                              blcli_execute "${${(C)${groupTypeString:r}//_/ }// /}" addCondition "${fullGroupName}" "${condition[2]}" "${condition[3]}" "${condition[4]}"

           

                                          else

           

                                              blcli_execute "${${(C)${groupTypeString:r}//_/ }// /}" addCondition "${fullGroupName}" "${condition[1]}" "${condition[2]}" "${condition[3]}" "${condition[4]}"

           

                                          fi

           

                                      fi

           

                                  done

           

                                  if [[ ${i} -gt 1 ]]

           

                                      then

           

                                      blcli_execute "${${(C)${groupTypeString:r}//_/ }// /}" setMatchAll "${fullGroupName}" "${matchAll}"

           

                                     

           

                                  fi

           

                              fi

           

                          fi

           

                      fi

           

                      parentGroupPath="${parentGroupPath:#/}/${groupName}" && print_variable "parentGroupPath"

           

                     

           

                  done <<< ${${fullGroupName/\//}//\//$'\n'}

           

              else

           

                  print_info "Group ${fullGroupName} exists..."

           

                  blcli_execute Group groupNameToId "${fullGroupName}" ${groupTypeId}

           

                  blcli_storeenv groupId

           

              fi

           

              print_debug2 "Exiting function: ${0}..."       

           

          }

           

           

           

          if i want to make a depot group i do like:

          createGroup "DEPOT_GROUP" "${depotGroup}" "DEPOT_GROUP"

           

          if i want to make a smart group w/ some condition i do:

          createGroup SMART_SERVER_GROUP "${serverGroup}/${groupName}" STATIC_SERVER_GROUP "true" "Class://SystemObject/Server,MY_PROP,equals,true"

          • 2. Re: Can I create Folders under Job using BLCli
            Aryan Anantwar

            Hi Rajeev,

                

            Yeah, JOB_FOLDER="/$LOB/$APP_NAME/Conditions", will not work as  is no folder 'conditions' inside APP_NAME.

             

            So, just run few another blcli to create this folder just before this line.

             

            i.e.

            PARENT_GROUP_ID=`blcli JobGroup groupNameToId $PARENT_GROUP "/$LOB/$APP_NAME"`

            JOB_GROUP_ID=`blcli JobGroup createJobGroup "Conditions" $PARENT_GROUP_ID`


            After these, You can use JOB_GROUP_ID wherever required.

                

            refer: https://docs.bmc.com/docs/display/bsacli83/JobGroup+-+createJobGroup

             

            Regards, 

            Aryan Anantwar

            • 3. Re: Can I create Folders under Job using BLCli
              Bill Robinson

              But that assumes the parent is there, and it might not be…  hence the function I wrote