Job state conditional tutorial

63 views
Skip to first unread message

errr00111

unread,
Dec 27, 2018, 2:20:29 AM12/27/18
to rundeck-discuss
Hi,
I can't find any tutorials about how to use Job state conditional. I want to use it to prevent certain actions from running simultaneously on the same host and make them wait for the running action to finish executing.
Are there any tutorials that show how to do something like that?

rac...@rundeck.com

unread,
Dec 28, 2018, 11:09:36 AM12/28/18
to rundeck-discuss
Hi,

Right now the documentation needs some update about this, basically you need to define the Job by Name or UUID and set the state as you want (succeeded, failed, aborted, timeout, failed-with-retry) that you need for apply some behavior (Halt or Fail when Halt) you can see that on "More Information" button:

Select a value for Running and/or Execution State, and the matched Job will be compared to the chosen values.

  • Either a Job UUID, or a Job Name is required to identify the job.
  • Execution State AND/OR Running must be entered

Condition indicates how the comparison should be evaluated.

If the condition does not evaluate to true, then the step will optionally Halt.

If Halt is enabled, when the condition is not true, the workflow will be halted with one of these results:

  • Fail When Halted - if true, the workflow will halt with a Failure status.
  • Status When Halted - if set, the workflow will halt with this status.
  • Otherwise, it will halt with Success status.
Regards!

errr00111

unread,
Dec 30, 2018, 4:31:25 AM12/30/18
to rundeck-discuss
Are those values for the job that should be blocked or the blocking job?
I mean, should I enter the UUID, name, and status for the running job that should block the other jobs?

rac...@rundeck.com

unread,
Dec 31, 2018, 12:06:35 PM12/31/18
to rundeck-discuss
Hi,

You can make reference to other job depending on if running or not, or depending on the last status.

I did make a little example with two jobs to play:

JobToHalt (The job that we need to halt)

<joblist>
 
<job>
 
<defaultTab>summary</defaultTab>
 
<description></description>
 
<executionEnabled>true</executionEnabled>
 
<id>c98072b6-9ca5-4ec6-96b2-d43e1ff852ef</id>
 
<loglevel>INFO</loglevel>
 
<name>JobToHalt</name>
 
<nodeFilterEditable>false</nodeFilterEditable>
 
<scheduleEnabled>true</scheduleEnabled>
 
<sequence keepgoing='false' strategy='node-first'>
 
<command>
 
<exec>sleep 20; echo "done"</exec>
 
</command>
 
</sequence>
 
<uuid>c98072b6-9ca5-4ec6-96b2-d43e1ff852ef</uuid>
 
</job>
</joblist>

And JobChecker (the job that should block JobToHalt)

<joblist>
 
<job>
 
<defaultTab>summary</defaultTab>
 
<description></description>
 
<executionEnabled>true</executionEnabled>
 
<id>d5401271-6b72-4f92-a31d-7493c7f7b365</id>
 
<loglevel>INFO</loglevel>
 
<name>CheckerJob</name>
 
<nodeFilterEditable>false</nodeFilterEditable>
 
<scheduleEnabled>true</scheduleEnabled>
 
<sequence keepgoing='false' strategy='parallel'>
 
<command>
 
<step-plugin type='job-state-conditional'>
 
<configuration>
 
<entry key='condition' value='Equals' />
 
<entry key='fail' value='true' />
 
<entry key='halt' value='true' />
 
<entry key='jobName' value='JobToHalt ' />
 
<entry key='jobUUID' value='c98072b6-9ca5-4ec6-96b2-d43e1ff852ef' />
 
<entry key='running' value='true' />
 
<entry key='status' value='Hey!' />
 
</configuration>
 
</step-plugin>
 
</command>
 
</sequence>
 
<uuid>d5401271-6b72-4f92-a31d-7493c7f7b365</uuid>
 
</job>
</joblist>

If you run the first job and go running the second one, you can see that the first job is stopped and generate a custom message ("Hey!") on "Activity" panel.

Best Regards!

errr00111

unread,
Jan 3, 2019, 5:54:18 AM1/3/19
to rundeck-discuss
Hi,
Thanks for the example.
What I want to do is, say I have a job called ProductDeploy, I don't want multiple instances of this job to run simultaneously on the same node, but it's OK to run it simultaneously on different nodes.

Assuming that there's currently an instance of this job running on node a, and I want to run it again on the same node, I want the second job to wait for the first one to finish (Regardless whether it was successful or not).

Is JobStateConditional what I need?

rac...@rundeck.com

unread,
Jan 3, 2019, 10:06:52 AM1/3/19
to rundeck-discuss
Hello!

Maybe a good option for that is making a script that runs your job with the behavior that you describe.

You can use RD CLI for that: https://rundeck.github.io/rundeck-cli/

Hope it helps!
Reply all
Reply to author
Forward
0 new messages