Dynamic field population from another job

111 views
Skip to first unread message

Ryan Tin

unread,
Aug 1, 2022, 8:20:08 PM8/1/22
to rundeck-discuss
Is there anyway to populate an option field with values from another job with regex applied it? Scenario is this
- Job 1, get list of tasks and pass it to job2.
- Job 2, has a field that is populated based on the list of task from job1 and use some regex to filter which job is available. 

rac...@rundeck.com

unread,
Aug 2, 2022, 9:28:46 AM8/2/22
to rundeck-discuss
Hi Ryan,

Yes, using the Job Reference Step you can pass options or data values to another job (the first job can use the multiline regex data capture plugin to pass the task list, pass that data value using the Job Reference Step to the second job, and then the second job can evaluate the passed data value in an inline script to execute anything, e.g: a curl call to execute a specific job). Take a look at this example.

Regards.

Ryan Tin

unread,
Aug 2, 2022, 12:48:46 PM8/2/22
to rundeck-discuss
Is it possible to create a dropdown box in the options? I wanna filter the jobs based regex and let the users choose what jobs to run. 

Ryan Tin

unread,
Aug 2, 2022, 12:49:09 PM8/2/22
to rundeck-discuss
And by jobs in my previous message, I meant tasks

Ryan Tin

unread,
Aug 2, 2022, 3:38:29 PM8/2/22
to rundeck-discuss
Also, I'm facing an issue when running a rake task through rundeck on a k8s pod. 
`/usr/local/bin/kubectl exec sample-app-844789d484-6v8ww -n rails-app -- /bin/sh -c "rake -T"`

This is the output

Run options: --seed 61257
# Running:
Finished in 0.001346s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips

rac...@rundeck.com

unread,
Aug 2, 2022, 6:05:01 PM8/2/22
to rundeck-discuss

Hi Ryan,

Probably the best approach to your use case is to store the desired job list in a JSON file as a remote option, in that way your user can select the job from a dropdown list.

Job 1 -> Creates a JSON file with the desired job list via inline script following this format, an awesome tool to create it could be JQ.
Job 2 -> Takes the JSON file and uses it as a remote (file) option, then the user can select the desired job to execute.

Here is a Job Definition Example of the second job:

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 6c6396f8-29a7-4911-b942-094aad1e15d9
  loglevel: INFO
  name: JobA
  nodeFilterEditable: false
  options:
  - enforced: true
    name: jobs
    required: true
    valuesUrl: file:/path/to/your/json/file.json
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - fileExtension: .sh
      interpreterArgsQuoted: false
      script: |-
        # just a friendly message
        echo "executing your job..."

        # run a job using Rundeck API
        curl -X POST \
          'http://localhost:4440/api/41/job/@option.jobs@/run' \
          --header 'Accept: application/json' \
          --header 'X-Rundeck-Auth-Token: cPOpGjTogNcem40eCkkPnDOU9W9udHKQ'
      scriptInterpreter: /bin/bash
    keepgoing: false
    strategy: node-first
  uuid: 6c6396f8-29a7-4911-b942-094aad1e15d9

Consider that, Process Automation (formerly “Rundeck Enterprise”) includes the Ruleset Strategy that allows you to design complex workflows depending on your option value, this is the easiest way actually.

Regarding your k8s issue, you can use this plugin to interact with your k8s cluster.

Hope it helps!

Reply all
Reply to author
Forward
0 new messages