Automic Workload Automation

 View Only
Expand all | Collapse all

Dynamically skip jobs in workflow

Michael Lowry

Michael LowryNov 07, 2017 10:15 AM

Legacy User

Legacy UserNov 08, 2017 10:18 AM

Anon Anon

Anon AnonNov 09, 2017 05:49 AM

  • 1.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 09:35 AM

    Hello,

    I am in the process of creating a generic workflow that will be run against multiple environments from the same automic client.  The workflow will be called from a separate automic job (wrapper).  In the wrapper we will set up various variables that will be passed through the generic workflow e.g. job login names.  I have this working fine. This will allow us to have the same generic workflow and all the jobs in the same automic client with different 'wrapper' objects calling it passing in the variables required.

    In the generic worklow there are certain jobs that I only want to execute for certain environments e.g. if I pass through a variable called ENVIRONMENT_NAME with the possible combinations ENV1, ENV2, ENV3, ENV4.

    How am I best constructing the workflow so that a job would only run if ENVIRONMENT_NAME = 'ENV1'?

    Do I just need to add a pre condition excluding the other 3 values?

     

    e.g.

    IF ENVIRONMENT_NAME <> 'ENV2'

      IF ENVIRONMENT_NAME <> 'ENV3'

        IF ENVIRONMENT_NAME <> 'ENV4'

          FINALLY EXECUTE TASK...

        ELSE

          SKIP

      ELSE

        SKIP

    ELSE

      SKIP

    Hope this makes sense?

    Dan



  • 2.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 09:58 AM
    I personally would us a kind of RUN_SWITCH method i.e:

    PRESCRIPT of the JOBS:
    :SET &MYNAME# = &$NAME#

    :SET &RUN_SWITCH# = GET_VAR(VARA.ENV_SWITCH,&MYNAME#)
    :PRINT "RUN_SWITCH for &MYNAME#: &RUN_SWITCH#"

    :IF &RUN_SWITCH# <> "RUN"
    :  STOP NOMSG,50,"RUN SWITCH: &RUN_SWITCH#"
    :ENDIF

    You create a static VARA with the Object Name as KEY and a String e.g. RUN as Value1
                               

    JOBS.WIN.ENV_SWITCH1RUN




    JOBS.WIN.ENV_SWITCH2NOT




    every JOBS checks the VARA object anf if it does not have RUN will be skipped.

    p2e5h2kq489i.jpghttps://us.v-cdn.net/5019921/uploads/editor/fz/p2e5h2kq489i.jpg" width="985">

    Hint: Put the script above into an INCLUDE for all of those jobs, its generic.

    With this you can easily create and change the logic.


  • 3.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 10:15 AM
    We do something very similar. :smile:


  • 4.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 10:30 AM
    Hello Wolfgang and Michael,

    Cheers for your responses ... sounds like a good plan ...

    So in my example how would it best to cater for the scenario where

    If ....
     
    ENVIRONMENT_NAME = 'ENV1' then JOBS.WIN.ENV_SWITCH1 runs

    ENVIRONMENT_NAME = 'ENV2' then JOBS.WIN.ENV_SWITCH1 does not run

    Would it be best having a variable object for each possible value of ENVIRONMENT_NAME? and then when i do a get var i can do something like ..

    :SET &RUN_SWITCH# = GET_VAR(&ENVIRONMENT_NAME#.VARA.ENV_SWITCH,&MYNAME#)
    or possibly have one variable object and then prefix the key name in that object with the value of the ENVIRONMENT_NAME so the GET_VAR would be ..

    :SET &RUN_SWITCH# = GET_VAR(VARA.ENV_SWITCH,&ENVIRONMENT_NAME#_&MYNAME#)
    And the values in the variable object would be:

               
    KEYVALUE_1
    ENV1_JOBS.WIN.ENV_SWITCH1RUN
    ENV2_JOBS.WIN.ENV_SWITCH1NOT

    Again .. hope that makes sense?

    Dan



  • 5.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 10:31 AM
    here is a small improvement, if there does not exist an entry in the ENV VARA it will be created automatically:

    :PRINT "...entering JOBI.ENV_SWITCH..."

    :SET &ENV_SWITCH_VARA# = "VARA.ENV_SWITCH"
    :SET &MYNAME# = &$NAME#

    :SET &RUN_SWITCH# = GET_VAR(&ENV_SWITCH_VARA#, &MYNAME#)
    :PRINT "RUN_SWITCH for &MYNAME#: &RUN_SWITCH#"

    :IF &RUN_SWITCH# = "" OR " "
    :  PRINT "Action for &MYNAME# NOT defined in &ENV_SWITCH_VARA#"
    :  PUT_VAR &ENV_SWITCH_VARA#, &MYNAME#, "not yet defined"
    :  PRINT "PUT_VAR &ENV_SWITCH_VARA#, &MYNAME#, not yet defined"
    :ENDIF

    :IF &RUN_SWITCH# <> "RUN"
    :  STOP NOMSG, 50, "RUN SWITCH from &ENV_SWITCH_VARA#: &RUN_SWITCH#"
    :ENDIF

    :PRINT "...leaving JOBI.ENV_SWITCH..."

    fd84rvpiqmaj.jpg


  • 6.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 11:09 AM
    O your response was quite the same time...

    Yes, I would create one VARA per ENV.
    :SET &RUN_SWITCH# = GET_VAR(&ENVIRONMENT_NAME#.VARA.ENV_SWITCH,&MYNAME#)



  • 7.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 11:14 AM
    Hello,

    Cheers again Wolfgang .... will give it a whirl and let you know how it goes.

    Thanks again.

    Dan


  • 8.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 11:37 AM
    We don't use prescript's.  We use workflow preconditions.   Seems prescripts could get in the way of someone trying to unit-test the job outside of its workflow in a non production client?


  • 9.  Dynamically skip jobs in workflow

    Posted Nov 07, 2017 01:19 PM
    Thats a matter how the whole thing is implemented. We don' use preconditions and do everything via prescripts and includes :-)

    Every ENV has its own ENV Variables and RUN configs.

    And Yes, one should think about how to deploy and test this on another system or client.


  • 10.  Dynamically skip jobs in workflow

    Posted Nov 08, 2017 08:46 AM
    Hello Folks,

    I have now managed to put a test wrapper and workflow together and all works as expected when I do all the work in the pre process of the jobs ..

    :SET &MYNAME# = &$NAME#

    :SET &RUN_JOB# = GET_VAR("&ENVIRONMENT#.VARA.RUN_JOB", "&MYNAME#", 1) :SET &RUN_SCRIPT# = GET_VAR("&ENVIRONMENT#.VARA.RUN_JOB", "&MYNAME#", 2)

    :PRINT "RUN_JOB for &MYNAME#: &RUN_JOB#"
    :PRINT "RUN_SCRIPT for &MYNAME#: &RUN_SCRIPT#"

    :IF &RUN_JOB# = "DO_NOT_RUN_JOB" : STOP NOMSG,50,"RUN JOB: &RUN_JOB#"
    :ENDIF
    As mentioned above ..

    Hint: Put the script above into an INCLUDE for all of those jobs, its generic.

    With this you can easily create and change the logic.

    How would I take this logic up into an INCLUDE?
    Would the include know the execution values of &MYNAME# and &ENVIRONMENT# at the time it was called?

    Cheers,

    Dan.



  • 11.  Dynamically skip jobs in workflow

    Posted Nov 08, 2017 10:10 AM
    Yes ist would.
    An include ist just an "outsourced" part of script (for multiple use) and its generated as it would be in preproces (or process or postprocess)...

    if you expand it in the (pre/- post-) process tab you see that its so to say part of the script...

    here is mine (working in 3 Jobs):

    :PRINT "...entering JOBI.ENV_SWITCH..."

    :SET &ENV_SWITCH_VARA# = "VARA.ENV_SWITCH"
    :SET &MYNAME# = &$NAME#

    :SET &RUN_SWITCH# = GET_VAR(&ENV_SWITCH_VARA#, &MYNAME#)
    :PRINT "RUN_SWITCH for &MYNAME#: &RUN_SWITCH#"

    :IF &RUN_SWITCH# = "" OR " "
    :  PRINT "Action for &MYNAME# NOT defined in &ENV_SWITCH_VARA#"
    :  PUT_VAR &ENV_SWITCH_VARA#, &MYNAME#, "not yet defined"
    :  PRINT "PUT_VAR &ENV_SWITCH_VARA#, &MYNAME#, not yet defined"
    :ENDIF

    :IF &RUN_SWITCH# <> "RUN"
    :  STOP NOMSG, 50, "RUN SWITCH from &ENV_SWITCH_VARA#: &RUN_SWITCH#"
    :ENDIF

    :PRINT "...leaving JOBI.ENV_SWITCH..."



  • 12.  Dynamically skip jobs in workflow

    Posted Nov 08, 2017 10:13 AM
    How would I take this logic up into an INCLUDE?

    just put the script part you want to (re-)use into a JOBI object.

    and call it with : INC JOBI.NAME
    imt79ngyugl6.jpg

    docu:
    https://docs.automic.com/documentation/WEBHELP/English/AWA/11.2/AE/11.2/All%20Guides/help.htm#uczaaz.htm%3FTocPath%3DUser%2520Guide%7CObjects%7CAlphabetical%2520Listing%7CInclude%7C_____0



  • 13.  Dynamically skip jobs in workflow

    Posted Nov 08, 2017 10:18 AM
    Cheers again Wolfgang ... Will give it a go :)


  • 14.  Dynamically skip jobs in workflow

    Posted Nov 08, 2017 10:50 AM
    the real cool thing for making them generic is that you cann pass a parameter when calling the include:

    : INC JOBI.TEST PARAM="Schubiduba"

    every PARAM in the include will be replaced by "Schubiduba"
    this works for scriot variables as well.

    3icesy7clqco.jpg




  • 15.  Dynamically skip jobs in workflow

    Posted Nov 09, 2017 02:54 AM
    Works a treat ... Cheers for your help Wolfgang.

    Dan


  • 16.  Dynamically skip jobs in workflow

    Posted Nov 09, 2017 05:49 AM
    You ' re welcome :-)