Go to step based on variable

74 views
Skip to first unread message

Andrea Favero

unread,
Jan 18, 2020, 8:50:45 AM1/18/20
to rundeck-discuss
Hello, I have this simple question:

As step 1, i have a shell script which performs some operations and outputs a variable at the end.

If the variable equals = foo, I want the job to continue from step 2.
If the variable equals = bar, I want the job to continue from step 3 (skipping step 2).
If the variable equals = baz, I want the job end with "success".

Is this possibile to achieve without Rundeck's pro workflow strategy?

Thanks!

Andrea

Reiner Acuña

unread,
Jan 18, 2020, 2:18:37 PM1/18/20
to rundeck-discuss
Hi Andrea,

A good way to do that is to use data variables (data passing) that can be caught by any step (and decide if that step is executable or not, as you see, it's basically scripting).

I leave an example that works as you want:

<joblist>
 
<job>
   
<context>
     
<options preserveOrder='true'>
       
<option enforcedvalues='true' name='variable' values='foo,bar,baz' valuesListDelimiter=',' />
     
</options>
   
</context>
   
<defaultTab>nodes</defaultTab>
   
<description></description>
   
<executionEnabled>true</executionEnabled>
   
<id>7091b22a-5e87-40ad-8728-5477ccd68646</id>
   
<loglevel>INFO</loglevel>
   
<name>JobEXAMPLE</name>
   
<nodeFilterEditable>false</nodeFilterEditable>
   
<scheduleEnabled>true</scheduleEnabled>
   
<sequence keepgoing='false' strategy='sequential'>
     
<command>
       
<plugins>
         
<LogFilter type='key-value-data'>
           
<config>
             
<logData>true</logData>
             
<regex>^(VARIABLE)\s*=\s*(.+)$</regex>
           
</config>
         
</LogFilter>
       
</plugins>
       
<script><![CDATA[echo "VARIABLE=@option.variable@"]]></script>
       
<scriptargs />
     
</command>
     
<command>
       
<script><![CDATA[if [ @data.VARIABLE@ = "foo" ]
then
    echo
"doing the step two."
fi
]]></script>
       
<scriptargs />
     
</command>
     
<command>
       
<script><![CDATA[if [ @data.VARIABLE@ = "bar" ]
then
    echo
"skipping step two, doing the step three"
fi
]]></script>
       
<scriptargs />
     
</command>
     
<command>
       
<script><![CDATA[if [ @data.VARIABLE@ = "baz" ]
then
    echo
"job success"
fi
]]></script>
       
<scriptargs />
     
</command>
   
</sequence>
   
<uuid>7091b22a-5e87-40ad-8728-5477ccd68646</uuid>
 
</job>
</joblist>


You have a good starting point about data passing here:


Hope it helps!

Andrea Favero

unread,
Jan 19, 2020, 7:02:39 PM1/19/20
to rundeck-discuss
Hello Reiner, thank you for your reply.
Yes, I did setup something similar, and this is what I've came up with:


if [ @data.test@ = "true" ]
then
    echo "doing the step three."
    /home/test/script_test_3.sh
fi


This works indeed correctly if I want all the scripts dispatched to the same node.
But what if the first script is on node A and the script inside the if condition ( /home/test/script_test_3.sh  in my example ) is in node B ?
Is this possible?

Thank you!
Andrea

Reiner Acuña

unread,
Jan 20, 2020, 8:16:02 AM1/20/20
to rundeck-discuss
Hi Andrea,

In this case you need to use Job Reference Step to some job pointing to a specific node (the nodes works on project level). Another way is to use a command to execute in that remote node in your step like this:

https://groups.google.com/d/msg/rundeck-discuss/8IGitGyuPwU/faPSqNinDAAJ

Job reference step documentation:

https://docs.rundeck.com/docs/manual/node-steps/builtin.html#job-reference-step

Job reference step example:

https://groups.google.com/d/msg/rundeck-discuss/C8KpsqBupmo/WzNj9dMyBwAJ

Regards!

Andrea Favero

unread,
Feb 19, 2020, 5:54:58 PM2/19/20
to rundeck-discuss
Thank you very much!! :)



Il giorno sabato 18 gennaio 2020 14:50:45 UTC+1, Andrea Favero ha scritto:
Reply all
Reply to author
Forward
0 new messages