Search code examples
rundeck

Rundeck - Reference Job: ${node.name} as Node filter


on Rundeck (3.2.6-20200427) I created two Jobs called testjob and subjob.

testjob should call reference job subjob.

In workflow of subjob, I added a task "Job Reference" and selected another job. There I set "Run as a" to "Node Step". See screenshot testjob-task1.

enter image description here

Then I entered '${node.name}' as Node filter.

enter image description here

Unfortunatelly, if I run testjob, then I got error:

1. generic/subjob: No nodes matched for the filters: NodeSet{includes={name=${node.name}, dominant=false, }}

What did I wrong? I didn't add option into workflow because I read, it is not needed if the job is run as a Node Step. Am I wrong? Also I'm wondering, why the error log doesn't tell like '...NodeSet{includes=node01, dominant=false, }}', it seems that the variable is not set properly there.


Solution

  • Testing directly with one job ${node.name} doesn't work as a filter, you can use some option (or string) that matches any node in your model source, as the following example (parent-child workflow using some option example).

    Parent Job:

    <joblist>
      <job>
        <context>
          <options preserveOrder='true'>
            <option name='optparent' value='node00' />
          </options>
        </context>
        <defaultTab>nodes</defaultTab>
        <description></description>
        <executionEnabled>true</executionEnabled>
        <id>3f94993d-665c-45da-8233-f95c0f69f665</id>
        <loglevel>INFO</loglevel>
        <name>Parent</name>
        <nodeFilterEditable>false</nodeFilterEditable>
        <plugins />
        <scheduleEnabled>true</scheduleEnabled>
        <sequence keepgoing='false' strategy='node-first'>
          <command>
            <jobref name='Child' nodeStep='true'>
              <arg line='-mynodes ${option.optparent}' />
              <uuid>badd942a-f4e7-41de-9588-1b5d255e34d8</uuid>
            </jobref>
          </command>
        </sequence>
        <uuid>3f94993d-665c-45da-8233-f95c0f69f665</uuid>
      </job>
    </joblist>
    

    Child Job:

    <joblist>
      <job>
        <context>
          <options preserveOrder='true'>
            <option name='mynodes' value='node00' />
          </options>
        </context>
        <defaultTab>nodes</defaultTab>
        <description></description>
        <dispatch>
          <excludePrecedence>true</excludePrecedence>
          <keepgoing>false</keepgoing>
          <rankOrder>ascending</rankOrder>
          <successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
          <threadcount>1</threadcount>
        </dispatch>
        <executionEnabled>true</executionEnabled>
        <id>badd942a-f4e7-41de-9588-1b5d255e34d8</id>
        <loglevel>INFO</loglevel>
        <name>Child</name>
        <nodeFilterEditable>false</nodeFilterEditable>
        <nodefilters>
          <filter>${option.mynodes}</filter>
        </nodefilters>
        <nodesSelectedByDefault>true</nodesSelectedByDefault>
        <plugins />
        <scheduleEnabled>true</scheduleEnabled>
        <sequence keepgoing='false' strategy='node-first'>
          <command>
            <exec>echo "hi"</exec>
          </command>
        </sequence>
        <uuid>badd942a-f4e7-41de-9588-1b5d255e34d8</uuid>
      </job>
    </joblist>