如何通过shell向rundeck rd程序提交参数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何通过shell向rundeck rd程序提交参数相关的知识,希望对你有一定的参考价值。

我想提交并执行需要选择的工作。

我目前不希望通过URL使用API​​。

是否可以使用rd命令执行需要的操作?

感谢Obi-Wan Kenobi。

rd run help
Run a Job. Specify option arguments after -- as "-opt value". Upload files as "-opt @path" or "-opt@ path".

Usage: run [options] -- -OPT VAL -OPT2 VAL -OPTFILE @filepath -OPTFILE2@ filepath...
    [--filter -F value] : A node filter string
    [--follow -f] : Follow execution output as it runs
    [--id -i value] : Run the Job with this IDENTIFIER
    [--job -j value] : Job job (group and name). Run a Job specified by Job name and group. eg: 'group/name'.
    [--loglevel -l /(debug|verbose|info|warning|error)/] : Run the command using the specified LEVEL. LEVEL can be debug, verbose, info, warning, error.
    [--outformat -% value] : Output format specifier for execution logs. You can use "%key" where key is one of:time,level,log,user,command,node. E.g. "%user@%node/%level: %log"
    [--progress -r] : Do not echo log text, just an indicator that output is being received.
    [--project -p /^[-_a-zA-Z0-9+][-._a-zA-Z0-9+]*$/] : Project name
    [--quiet -q] : Echo no output. Combine with -f/--follow to wait silently until the execution completes. Useful for non-interactive scripts.
    [--raw] : Treat option values as raw text, so that '-opt @value' is sent literally
    [--restart -t] : Restart from the beginning
    [--at -@ value] : Run the job at the specified date/time. ISO8601 format (yyyy-MM-dd'T'HH:mm:ssXX)
    [--delay -d /(d+[smhdwMY]s*)+/] : Run the job at a certain time from now. Format: ##[smhdwMY] where ## is an integer and the units are seconds, minutes, hours, days, weeks, Months, Years. Can combine units, e.g. "2h30m", "20m30s"
    [--tail -T value] : Number of lines to tail from the end, default: 1
    [--user -u value] : A username to run the job as, (runAs access required).
答案

使用此示例工作定义:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='opt1' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>9b9568c2-00c4-4e7c-a15d-5e007f980f3a</id>
    <loglevel>INFO</loglevel>
    <name>HelloWorld</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <exec>echo "hello ${option.opt1}"</exec>
      </command>
    </sequence>
    <uuid>9b9568c2-00c4-4e7c-a15d-5e007f980f3a</uuid>
  </job>
</joblist>

您可以在RD CLI上以这种方式运行传递选项值的作业:

rd run -j HelloWorld -p ProjectDEMO -- -opt1 "World"

请记住在之前设置RD_URL环境变量:

export RD_URL=http://your-host:4440

以上是关于如何通过shell向rundeck rd程序提交参数的主要内容,如果未能解决你的问题,请参考以下文章

rundeck自动化运维

Javascript生成json之后提交表单向其他web项目出现问题,传参乱码。

如何从 Chef 获取 rundeck 的节点清单

如何以只读方式访问一个,多个或所有Rundeck项目的方式手动创建Rundeck用户

如何完全卸载RUNDECK

Rundeck部署和基本使用