theirpuppet
theirpuppet

Reputation: 33

Rundeck: Pass data between jobs

I'm trying to follow the instructions provided at https://stackoverflow.com/a/61802154 to pass output from one job as input into another job.

Job1 sets up the k/v data

- defaultTab: output
  description: ''
  executionEnabled: true
  id: b6656d3b-2b32-4554-b224-52bd3702c305
  loglevel: INFO
  name: job1
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'name: rdnode01'
  nodesSelectedByDefault: true
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: output k/v
      exec: echo RUNDECK:DATA:MYNUM=123
    - description: test k/v
      exec: echo ${data.MYNUM}
    keepgoing: false
    pluginConfig:
      LogFilter:
      - config:
          invalidKeyPattern: \s|\$|\{|\}|\\
          logData: 'true'
          regex: ^RUNDECK:DATA:\s*([^\s]+?)\s*=\s*(.+)$
          replaceFilteredResult: 'false'
        type: key-value-data
    strategy: node-first
  uuid: b6656d3b-2b32-4554-b224-52bd3702c305

Job2 will output that k/v data

- defaultTab: output
  description: ''
  executionEnabled: true
  id: c069e7d3-2d1f-46f2-a4d8-15eb19761daf
  loglevel: INFO
  name: job2
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'name: rdnode01'
  nodesSelectedByDefault: true
  options:
  - name: option_for_receive
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: echo ${option.option_for_receive}
    keepgoing: false
    strategy: node-first
  uuid: c069e7d3-2d1f-46f2-a4d8-15eb19761daf

Wrapper runs the job references as node steps and passes the data from job1 to job2

- defaultTab: output
  description: ''
  executionEnabled: true
  id: 5a62cabf-ffc2-45d1-827b-156f4134a082
  loglevel: INFO
  name: wrapper job
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'name: rdnode01'
  nodesSelectedByDefault: true
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: job1
      jobref:
        childNodes: true
        group: ''
        name: job1
        nodeStep: 'true'
        uuid: b6656d3b-2b32-4554-b224-52bd3702c305
    - description: job2
      jobref:
        args: -option_for_receive ${data.MYNUM}
        childNodes: true
        group: ''
        name: job2
        nodeStep: 'true'
        uuid: c069e7d3-2d1f-46f2-a4d8-15eb19761daf
    keepgoing: false
    strategy: node-first
  uuid: 5a62cabf-ffc2-45d1-827b-156f4134a082

This the formatted text from the execution log

11:26:39 [rundeck@rdnode01 1@node=rdnode01/1][NORMAL] RUNDECK:DATA:MYNUM=123
11:26:40 [rundeck@rdnode01 1@node=rdnode01/1][NORMAL] {"MYNUM":"123"}
11:26:40 [rundeck@rdnode01 1@node=rdnode01/2][NORMAL] 123
11:26:41 [rundeck@rdnode01 2@node=rdnode01/1][NORMAL] '${data.MYNUM}'

This is what it looks like on the screen: screenshot

As you can see, job2 is outputting '${data.MYNUM}' instead of the actual contents. Thus I think there's a syntax issue somewhere.

Upvotes: 0

Views: 330

Answers (1)

MegaDrive68k
MegaDrive68k

Reputation: 4325

The data values are generated in the job context, in that case, the "Wrapper Job" (Parent Job in the Rundeck terminology) doesn't know about that data variable in their context (generated in the first job).

If you want to pass that data value to another job, call the second one from the first one in the following way (Workflow Node Step):

JobA:

- defaultTab: output
  description: ''
  executionEnabled: true
  id: b6656d3b-2b32-4554-b224-52bd3702c305
  loglevel: INFO
  name: job1
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'name: localhost '
  nodesSelectedByDefault: true
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: output k/v
      exec: echo RUNDECK:DATA:MYNUM=123
    - description: test k/v
      exec: echo ${data.MYNUM}
    - jobref:
        args: -option_for_receive ${data.MYNUM}
        childNodes: true
        group: ''
        name: job2
        nodeStep: 'true'
        uuid: c069e7d3-2d1f-46f2-a4d8-15eb19761daf
    keepgoing: false
    pluginConfig:
      LogFilter:
      - config:
          invalidKeyPattern: \s|\$|\{|\}|\\
          logData: 'true'
          regex: ^RUNDECK:DATA:\s*([^\s]+?)\s*=\s*(.+)$
          replaceFilteredResult: 'false'
        type: key-value-data
    strategy: node-first
  uuid: b6656d3b-2b32-4554-b224-52bd3702c305

JobB:

- defaultTab: output
  description: ''
  executionEnabled: true
  id: c069e7d3-2d1f-46f2-a4d8-15eb19761daf
  loglevel: INFO
  name: job2
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'name: localhost '
  nodesSelectedByDefault: true
  options:
  - name: option_for_receive
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: echo ${option.option_for_receive}
    keepgoing: false
    strategy: node-first
  uuid: c069e7d3-2d1f-46f2-a4d8-15eb19761daf

Upvotes: 1

Related Questions