9 Replies Latest reply on Jul 15, 2013 4:20 AM by Reg Smith

    How to determine jobtype from blcli given job path/dbid

      Hi

       

      Does anyone know how I can determine a jobtype (Deploy,NSH Script, batch etc) given the full path to the job (or job DBID). Many of the blcli commands take the jobtype as a required argument but I can't find a blcli command to return the type of job.

       

      At the moment we are having to manually feed in the jobtype as a parameter to a script, it would make the script more user friendly to not have to explicitly do this if possible.

       

      Many thanks

       

      Reg

        • 1. Re: How to determine jobtype from blcli given job path/dbid
          Siddu angadi

          Hi Reg,

           

          Refer the below command which get you job type if you job DB Key:

           

           

          blcli_execute Job getType

          • 2. Re: How to determine jobtype from blcli given job path/dbid

            Hi Siddu

             

             

             

            Thanks – that command doesn’t seem to be in the blcli help.

             

             

             

            The only thing is, to get a DBID for job, don’t you have to tell it the jobtype..which I want to determine in the script so it would bseem a bit “checken and egg” (BTW - it’s your promotion script actually, we want to remove the need to supply the Job type as a parameter to the script J )

             

             

             

            Best wishes

             

             

             

            Reg

            • 3. Re: How to determine jobtype from blcli given job path/dbid
              Siddu angadi

              Oh it is my baby..:)

               

              You can not automate that, you have to pass the job type. I have already tried long back, it is not possible.

               

              Thanks

              Siddu

              • 4. Re: How to determine jobtype from blcli given job path/dbid
                Bill Robinson

                w/ the full path to the job, you don't have enough information.  if you have the parent group, you could loop through each job in the group, do a name match and figure it out from there.

                 

                what specifically are you trying to do here ?

                • 5. Re: How to determine jobtype from blcli given job path/dbid

                  Hi Bill

                   

                  Thanks - It's a promotion script that copies a job, locks the package and removes/adds ACL's. At the moment the input parameters are:

                  1. The target environment to promote to (which is actually equates to a job folder tha tthe job will be copied to)
                  2. The full job path (from which we can extract teh group bu splitting the basename off the full path
                  3. The job type - this is what we want to remove the need to specify manually. The script needs to know the jobtype to use in many of the blcli_execute commands.

                   

                  While it's not rocket science having to specify BatchJob/DeployJob/FileDeployjob/NSHScriptjob for the jobtype in item 3 it still invites user error and on the face of it seems like we ought to be able to figure out the job type if we have the full path to the job to make the script a little more user friendly?

                   

                  best wishes

                   

                  Reg

                  • 6. Re: How to determine jobtype from blcli given job path/dbid
                    Bill Robinson

                    Can you list the blcli commands you need to run for the promotion process ?

                    • 7. Re: How to determine jobtype from blcli given job path/dbid

                      Hi Bill

                       

                      It's a large NSH script that does a number of things like lock the package, copy the job to another folder and add/remove acl policies as appropriate to the environment being promoted to, it's a bit big to put inline here, but the calls that require the use of the jobtype are all getDBKeyByGroupAndName

                       

                      e.g.

                      blcli_execute ${OBJECT_TYPE} getDBKeyByGroupAndName ${DestJobFolder} ${JOB_NAME}"

                       

                      At the moment the object type (i.e. the jobtype) is supplied manually as a parameter to the script (along with the full path to the job to promote and the environment to promote to), the goal is to have the script figure out the job type itself from the job full path.

                       

                      Best wishes

                       

                      Reg

                      • 8. Re: How to determine jobtype from blcli given job path/dbid
                        Bill Robinson

                        so you could do like:

                         

                        blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true

                        blcli_setoption serviceProfileName defaultProfile

                        blcli_setoption roleName BLAdmins

                        blcli_connect

                         

                        fullJobPath="/Workspace/Test/AuditForCopy"

                         

                        jobGroup="${fullJobPath%/*}"

                        targetJobName="${fullJobPath##*/}"

                         

                        blcli_execute JobGroup groupNameToId "${jobGroup}"

                        blcli_storeenv jobGroupId

                         

                        blcli_execute Job findAllHeadersByGroup ${jobGroupId}

                        blcli_execute Utility storeTargetObject jobHeaders

                        blcli_execute Utility listLength

                        blcli_storeenv listLength

                         

                        for i in {0..$((${listLength}-1))}

                                do

                                blcli_execute Utility setTargetObject jobHeaders

                                blcli_execute Utility listItemSelect ${i}

                                blcli_execute Utility setTargetObject

                                blcli_execute SJobHeader getName

                                blcli_storeenv jobName

                                if [[ "${targetJobName}" = "${jobName}" ]]

                                        then

                                        blcli_execute SJobHeader getDBKey

                                        blcli_storeenv jobKey

                         

                                        echo "Do some stuff to ${jobKey}"

                                        break

                                fi

                        done

                         

                        if the group had a ton of jobs, this won't be very efficient.  once you have the dbkey you should be set.  there is no way to get the text type name from the job object though (eg AUDIT_JOB) - you can get the number type like:

                         

                        blcli_execute Job findByDBKey ${jobKey}

                        blcli_execute Job getType

                        blcli_storeenv jobTypeId

                        • 9. Re: How to determine jobtype from blcli given job path/dbid

                          Thanks Bill, we've used your method in our bigger script now as you've outlined above - we can live with any inefficiency.

                           

                          Much appreciated!

                           

                          Best wishes

                           

                          Reg