简体   繁体   English

如何通过 Rundeck 运行更复杂的作业依赖项

[英]How can I run more complex job dependencies via Rundeck

I'm currently testing Rundeck for some PoCs I'm working on.我目前正在为我正在研究的一些 PoC 测试 Rundeck。 I currently only have it running on a single machine via docker, so I don't have access to multiple nodes.我目前只能通过 docker 在一台机器上运行它,所以我无法访问多个节点。

I want to simulate the following job dependencies:我想模拟以下工作依赖项:

JobA is needed for JobB and JobC. JobB 和 JobC 需要 JobA。 But JobB and JobC must run in parallel.但是 JobB 和 JobC必须并行运行。

JobC must run if the current local time is 9:00am.如果当前本地时间是上午 9:00,则必须运行 JobC。 Doesn't matter if Job A is finished/started yet or not.作业 A 是否已完成/开始并不重要。

All this should be able to easily scale and expand up to several hundreds of Jobs.所有这些都应该能够轻松扩展和扩展到数百个 Job。

Can some of you guys possibly help me?你们中的一些人可以帮助我吗? I have tried several configurations including the Plug-in Job State.我尝试了几种配置,包括插件作业状态。 I somehow can't get this to work.我不知何故无法让它工作。 The best I can do is run all the jobs either sequential or parallel.我能做的最好的事情就是按顺序或并行运行所有作业。

The best (and easiest) way to achieve that is to use the ruleset strategy (only available on PagerDuty Process Automation On Prem, formerly "Rundeck Enterprise") calling your jobs using the job reference step .实现这一目标的最佳(也是最简单)方法是使用规则集策略(仅在 PagerDuty Process Automation On Prem 上可用,以前称为“Rundeck Enterprise”)使用作业参考步骤调用您的作业。

So, on the community version, the "workaround" is to call the jobs from a Parent Job via Rundeck API , which basically is about scripting the custom workflow behavior, eg :因此,在社区版本中,“解决方法”是通过Rundeck API从父作业调用作业,这基本上是关于编写自定义工作流行为的脚本, 例如

JobA工作A

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: b156b3ed-fde6-4fdc-af81-1ee919edc4ff
  loglevel: INFO
  name: JobA
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: whoami
    keepgoing: false
    strategy: node-first
  uuid: b156b3ed-fde6-4fdc-af81-1ee919edc4ff

JobB工作B

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 4c46c795-20c9-47a8-aa2e-e72f183b150f
  loglevel: INFO
  name: JobB
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: whoami
    keepgoing: false
    strategy: node-first
  uuid: 4c46c795-20c9-47a8-aa2e-e72f183b150f

JobC (runs every day at 9.00 AM, no matter the JobA execution). JobC(每天上午 9 点运行,无论 JobA 执行如何)。

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: ce45c4d1-1350-407b-8001-2d90daf49eaa
  loglevel: INFO
  name: JobC
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  schedule:
    month: '*'
    time:
      hour: '09'
      minute: '00'
      seconds: '0'
    weekday:
      day: '*'
    year: '*'
  scheduleEnabled: true
  sequence:
    commands:
    - exec: whoami
    keepgoing: false
    strategy: node-first
  uuid: ce45c4d1-1350-407b-8001-2d90daf49eaa

ParentJob (all the behavior logic is inside a bash script, needs jq tool to work) ParentJob(所有行为逻辑都在 bash 脚本中,需要jq工具才能工作)

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 6e67020c-7293-4674-8d56-5db811ae5745
  loglevel: INFO
  name: ParentJob
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: A friendly starting message
      exec: echo "starting..."
    - description: Execute JobA and Get the Status
      fileExtension: .sh
      interpreterArgsQuoted: false
      plugins:
        LogFilter:
        - config:
            invalidKeyPattern: \s|\$|\{|\}|\\
            logData: 'true'
            regex: ^(job_a_exec_id)\s*=\s*(.+)$
          type: key-value-data
      script: "# execute JobA\nexec_id=$(curl -s -X POST \\\n  \"http://localhost:4440/api/41/job/b156b3ed-fde6-4fdc-af81-1ee919edc4ff/run\"\
        \ \\\n  --header \"Accept: application/json\" \\\n  --header \"X-Rundeck-Auth-Token:\
        \ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd\" | jq .id)\n  \necho \"job_a_exec_id=$exec_id\""
      scriptInterpreter: /bin/bash
    - description: Time to execute the Job
      exec: sleep 2
    - description: 'Get the execution Status '
      fileExtension: .sh
      interpreterArgsQuoted: false
      plugins:
        LogFilter:
        - config:
            invalidKeyPattern: \s|\$|\{|\}|\\
            logData: 'false'
            regex: ^(job_a_exec_status)\s*=\s*(.+)$
          type: key-value-data
      script: "exec_status=$(curl -s -X GET \\\n  'http://localhost:4440/api/41/execution/@data.job_a_exec_id@'\
        \ \\\n  --header 'Accept: application/json' \\\n  --header 'X-Rundeck-Auth-Token:\
        \ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd' | jq -r .status)\n  \necho \"job_a_exec_status=$exec_status\""
      scriptInterpreter: /bin/bash
    - description: 'Run JobB and JobC pararelly, depending on JobA Execution Status'
      fileExtension: .sh
      interpreterArgsQuoted: false
      script: "# Now execute JobB and JobC depending on the JobA final status (dependency)\n\
        \nif [ @data.job_a_exec_status@ = \"succeeded\" ]; then\n  echo \"Job A execition\
        \ is OK, running JobB and JobC pararelly...\"\n \n  # JobB \n  curl -X POST\
        \ \\\n  \"http://localhost:4440/api/41/job/4c46c795-20c9-47a8-aa2e-e72f183b150f/run\"\
        \ \\\n  --header \"Accept: application/json\" \\\n  --header \"X-Rundeck-Auth-Token:\
        \ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd\" &\n  \n  # JobC\n  curl -X POST \\\n\
        \  \"http://localhost:4440/api/41/job/ce45c4d1-1350-407b-8001-2d90daf49eaa/run\"\
        \ \\\n  --header \"Accept: application/json\" \\\n  --header \"X-Rundeck-Auth-Token:\
        \ 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd\" &\nelse\n  echo \"Job A has failed, dependencey\
        \ failed\"\nfi"
      scriptInterpreter: /bin/bash
    - description: A friendly ending message
      exec: echo "done."
    keepgoing: false
    strategy: node-first
  uuid: 6e67020c-7293-4674-8d56-5db811ae5745

Parent Job's JobB/JobC launching script:父作业的 JobB/JobC 启动脚本:

# Now execute JobB and JobC depending on the JobA final status (dependency)

if [ @data.job_a_exec_status@ = "succeeded" ]; then
  echo "Job A execition is OK, running JobB and JobC pararelly..."
 
  # JobB 
  curl -X POST \
  "http://localhost:4440/api/41/job/4c46c795-20c9-47a8-aa2e-e72f183b150f/run" \
  --header "Accept: application/json" \
  --header "X-Rundeck-Auth-Token: 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd" &
  
  # JobC
  curl -X POST \
  "http://localhost:4440/api/41/job/ce45c4d1-1350-407b-8001-2d90daf49eaa/run" \
  --header "Accept: application/json" \
  --header "X-Rundeck-Auth-Token: 45hNfblPiF6C1l9CfJeG37l08oAgs0Gd" &
else
  echo "Job A has failed, dependencey failed"
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用杯子将更多作业打印为一项作业 - How can I print more jobs as one job using cups 如何通过 Bash 脚本在 SFTP 会话中运行命令? - How Can I Run Commands In A SFTP Session Via A Bash Script? 如何从在Docker主机中运行的主机运行复杂的docker命令? - How can I run a complex docker command from host machine that runs in the docker host? 如何在 github 中找到一份工作,每天随机运行 1 到 50 次? - how can I make a job in github action run randomly between 1 and 50 times a day? 如何为此脚本添加循环以运行多个作业运行 - how can i add a loop to this script to run through multipul job runs 如何在 Gitlab 作业的后台运行 gradle 应用程序(nohup 在 gitlab 中不起作用) - How can I run gradle apps in background in Gitlab job (nohup is not working in gitlab) 如何在变量中grep复杂的字符串? - How can I grep complex strings in variables? Rundeck跨作业步骤共享变量 - Rundeck sharing variables across job steps 如何运行生成 tmux session 的 cron 作业? (苹果系统) - How do I run a cron job that spawns a tmux session? (MacOS) 如何通过SSH运行Shell脚本,以使远程计算机的环境与本地计算机的环境相似? - How can I run a shell script via SSH such that the environment of the remote computer is similar to that of the local computer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM