如何将选项传递给Rundeck作业Webhook URL [英] How to pass options to Rundeck job webhook URL
问题描述
我已经在Rundeck定义了一个Webhook来运行特定作业.该作业定义了3个选项:$ {option.VMName},$ {option.CPU}和$ {option.Memory}.作业本身被定义为本地powershell脚本,并执行为:powershell $ {scriptfile} $ {option.VMName} $ {option.CPU} $ {option.Memory}.这已经过测试并且可以正常工作.
I have defined a webhook in Rundeck to run a particular job. This job has 3 options defined: ${option.VMName}, ${option.CPU} and ${option.Memory}. The job itself is defined as a local powershell script and executes as: powershell ${scriptfile} ${option.VMName} ${option.CPU} ${option.Memory}. This is tested and works fine.
我现在想调用webhook POST URL,以便在定义了这些选项的情况下(通过Web仪表板,使用PowerShell)远程触发作业.我尝试将选项添加到URL的末尾,但未成功:
I would now like to invoke the webhook POST URL so that the job is remotely triggered (from a web dashboard, using PowerShell) with these options defined. I tried, unsuccessfully, adding the options to the end of my URL:
http://mywebhookuri#myjobname?opt.VMName=$VMName&opt.CPU=$CPU&opt.Memory=$Memory
http://mywebhookuri#myjobname?VMName=$VMName&CPU=$CPU&Memory=$Memory
以下PowerShell代码用于调用Webhook:
The following PowerShell code is being used to invoke the webhook:
$WebHookURI = "http://mywebhookuri#myjobname"
$header = @{}
$header.add("Content-Type","text/plain")
$body = @{} | ConvertTo-Json
$result = Invoke-RestMethod -Method Post -Uri $WebHookURI -Body $body -Headers $header
webhook插件和运行作业用法的文档状态为该插件收到的JSON可用于提供选项,节点过滤器和运行方式用户",但未显示明确的例子之一.
The documentation for the webhook plug-in and run-job usage state that "The JSON that is received by the plugin can be used to supply options, node filter, and the Run As user", but doesn't show a clear example of either.
如何将这些选项成功传递到Webhook URL?
How do I successfully pass these options to the webhook URL?
推荐答案
遵循此中定义该选项>方式,后来调用传递JSON数据,我做了一个示例,但使用了cURL:
Following the documentation, you need to define the option in this way, and later call passing a JSON data, I did an example but using cURL:
curl -H "Content-Type: application/json" -X POST -d '{"field1":"hello world"}' http://yourhost:4440/api/34/webhook/3moY0Ru1zxl5gM0tpVlecJ5BN1LPyhsx#New_Hook
这是该职位定义示例:
<joblist>
<job>
<context>
<options preserveOrder='true'>
<option name='opt1' />
</options>
</context>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>e97efb53-99a6-4e5a-80b7-a1b055866f43</id>
<loglevel>INFO</loglevel>
<name>HelloWorld</name>
<nodeFilterEditable>false</nodeFilterEditable>
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<exec>echo ${option.opt1}</exec>
</command>
</sequence>
<uuid>e97efb53-99a6-4e5a-80b7-a1b055866f43</uuid>
</job>
</joblist>
这篇关于如何将选项传递给Rundeck作业Webhook URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!