繁体   English   中英

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

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

我目前正在为我正在研究的一些 PoC 测试 Rundeck。 我目前只能通过 docker 在一台机器上运行它,所以我无法访问多个节点。

我想模拟以下工作依赖项:

JobB 和 JobC 需要 JobA。 但是 JobB 和 JobC必须并行运行。

如果当前本地时间是上午 9:00,则必须运行 JobC。 作业 A 是否已完成/开始并不重要。

所有这些都应该能够轻松扩展和扩展到数百个 Job。

你们中的一些人可以帮助我吗? 我尝试了几种配置,包括插件作业状态。 我不知何故无法让它工作。 我能做的最好的事情就是按顺序或并行运行所有作业。

实现这一目标的最佳(也是最简单)方法是使用规则集策略(仅在 PagerDuty Process Automation On Prem 上可用,以前称为“Rundeck Enterprise”)使用作业参考步骤调用您的作业。

因此,在社区版本中,“解决方法”是通过Rundeck API从父作业调用作业,这基本上是关于编写自定义工作流行为的脚本, 例如

工作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

工作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(每天上午 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(所有行为逻辑都在 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

父作业的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM