【问题标题】:Rundeck - flow execution with error handlerRundeck - 带有错误处理程序的流程执行
【发布时间】:2021-06-25 19:14:25
【问题描述】:

默认错误处理程序以某种方式工作,如果任何作业序列未以非零状态结束,则它进入错误处理程序流。

我想实现流程,如果API端点返回204,我需要执行一些依赖操作。

我正在考虑使用错误处理程序来执行此操作,但我如何处理返回状态 204,因为它只是处理错误处理程序中的非零状态流。

【问题讨论】:

    标签: rundeck


    【解决方案1】:

    在 Rundeck Enterprise 上,您可以使用规则集策略来执行此操作(例如,捕获退出代码并将其放在数据选项上以决定是否运行另一个作业),请查看 this

    在社区版本中,您可以编写脚本,通过以下方式管理脚本步骤中的行为(在我的示例中,我只想检测在选项中定义的 127 错误):

    作业定义示例:

    <joblist>
      <job>
        <context>
          <options preserveOrder='true'>
            <option name='code_to_catch' value='127' />
          </options>
        </context>
        <defaultTab>nodes</defaultTab>
        <description></description>
        <executionEnabled>true</executionEnabled>
        <id>ab58e8e3-78f8-4a60-b6fc-4ad1167aa3a4</id>
        <loglevel>INFO</loglevel>
        <name>HelloWorld</name>
        <nodeFilterEditable>false</nodeFilterEditable>
        <plugins />
        <scheduleEnabled>true</scheduleEnabled>
        <sequence keepgoing='false' strategy='node-first'>
          <command>
            <fileExtension>.sh</fileExtension>
            <script><![CDATA[date-foo-bar # intentional error
    mycode=$(printf '%d\n' $?)
    
    case $mycode in
    @option.code_to_catch@)
      echo "Executing actions for @option.code_to_catch@ error"
      ## also, you can run any job using RD-CLI (https://rundeck.github.io/rundeck-cli/) 
      ## or Rundeck API (https://docs.rundeck.com/docs/api/rundeck-api.html)
      ;;
    0)
      echo "all ok!"
      exit 0
      ;;
    esac
    
    ]]></script>
            <scriptargs />
            <scriptinterpreter>/bin/bash</scriptinterpreter>
          </command>
        </sequence>
        <uuid>ab58e8e3-78f8-4a60-b6fc-4ad1167aa3a4</uuid>
      </job>
    </joblist>
    

    如您所见,您可以使用内联脚本捕获错误代码,然后如果您愿意,可以使用 RD-CLI 运行另一个作业。

    【讨论】:

    • 我有 rundeck 企业,但没有正确理解如何从上一个参考作业中捕获返回代码,我知道我们有“result.resultCode”和“execution.status”但两个规则集规则对我不起作用。
    • 嗨!对于 Rundeck Enterprise 相关问题,请联系专门的支持团队,他们会尽快为您提供帮助 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 2019-05-31
    • 2015-04-27
    • 1970-01-01
    相关资源
    最近更新 更多