[英]Rundeck -> how can we pass the captured Key Value Data into the mail Template
[英]How can I pass captured data between two Rundeck Job References?
我试图弄清楚在 Rundeck 中是否可以从一个作业参考生成 output,将其捕获为全局变量,然后将该变量传递给第二个作业参考。
步骤 1 在节点 WinServer1 上执行 PowerShell 脚本。 output 是一个 FQDN(例如,workstation1.yadayada.com)。 我有一个键/值/数据过滤器,它捕获这个 output 作为主机名。 它可以通过 ${data.hostname*@WinServer1} 访问。
第 2 步使用以下内容创建全局变量:
值:${data.hostname*@WinServer1}
组: 出口
名称:主机名
第 3 步是对 output 的测试。
Write-Host "data.hostname = @data.hostname@"
Write-Host "export.hostname = @export.hostname@"
这些命令的 output 符合预期:
data.hostname = 工作站1.yadayada.com
export.hostname = 工作站1.yadayada.com
就本示例而言,第 1 步是与上图所示相同的 PowerShell 代码。 output如下:
数据.主机名 =
出口.主机名 =
在作业参考 2 中,我希望 data.hostname 为空,但我希望 export.hostname 包含station1.yadayada.com,因为我将其设为全局变量。 我是否误解了全局变量在 Rundeck 中的工作方式? 有没有办法完成我想做的事情? 我很乐意提供可能有助于解决此问题的任何其他信息。
我尝试过的其他一些事情
第二个作业需要一个选项来通过作业参考步骤“接收”第一个作业中生成的数据值(您将在“参数”文本框上作为参数传递)。 我举个例子:
工作一:
<joblist>
<job>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>d73f5404-371a-49b6-af7e-7951c2dd859a</id>
<loglevel>INFO</loglevel>
<name>JobOne</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<description>STEP 1: GENERATE THE DATA VALUE</description>
<fileExtension>.ps1</fileExtension>
<plugins>
<LogFilter type='key-value-data'>
<config>
<logData>true</logData>
<regex>^(THECAR)\s*=\s*(.+)$</regex>
</config>
</LogFilter>
</plugins>
<script><![CDATA[# generate data
Write-Host "THECAR=bmw"]]></script>
<scriptargs />
<scriptinterpreter>powershell.exe</scriptinterpreter>
</command>
<command>
<description>STEP 2: TEST THE DATA VALUE</description>
<fileExtension>.ps1</fileExtension>
<script><![CDATA[# print the data values
Write-Host "Testing the data value..."
Write-Host "My car is an @data.THECAR@"]]></script>
<scriptargs />
<scriptinterpreter>powershell.exe</scriptinterpreter>
</command>
<command>
<description>STEP 3: CALL THE JOBTWO AND SEND THE DATA VALUE TO JOBTWO OPTION DEFINED</description>
<jobref name='JobTwo' nodeStep='true'>
<arg line='-option_for_receive ${data.THECAR}' />
<uuid>a3191daf-eceb-4162-8f44-c8fe5b620ecc</uuid>
</jobref>
</command>
</sequence>
<uuid>d73f5404-371a-49b6-af7e-7951c2dd859a</uuid>
</job>
</joblist>
工作二:
<joblist>
<job>
<context>
<options preserveOrder='true'>
<option name='option_for_receive' />
</options>
</context>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>a3191daf-eceb-4162-8f44-c8fe5b620ecc</id>
<loglevel>INFO</loglevel>
<name>JobTwo</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<fileExtension>.ps1</fileExtension>
<script><![CDATA[# print the option (that receives data value from JobONE)
Write-Host "The JobONE car is: @option.option_for_receive@"
# all done.]]></script>
<scriptargs />
<scriptinterpreter>powershell.exe</scriptinterpreter>
</command>
</sequence>
<uuid>a3191daf-eceb-4162-8f44-c8fe5b620ecc</uuid>
</job>
</joblist>
结果在这里。
我发现最简单的方法是使用 python 库 json_kvs https://github.com/mlubkin/json_kvs
您可以在第一步编写变量并在第二步读取您也可以使用您的 jobId 作为 scope 在多个作业中使用相同的 json 文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.