2024-05-15 00:15:38 发布
网友
我试图在rundeck中运行python请求,它在URL for GET方法中硬编码键值的情况下对我有效。但我想使用rundeck选项,以便在运行时传递键值。请让我知道python中的步骤。 这对我在bash中的工作很好。在rundeck中创建选项后,我在脚本中使用了以下代码
Bash脚本 A=@option.Adata@ curl--location-k--request GET“URL?Adata=$A&;selector=A,B,C”\
提前谢谢
RK
您可以用与Bash内联脚本相同的方式传递选项,只需确保在调用字符串文本框中使用python解释器路径,在“文件扩展名”文本框中使用“.py”(如果在创建或编辑作业时单击“高级”按钮,这两个选项都可以访问)
我举一个例子:
<joblist> <job> <context> <options preserveOrder='true'> <option name='name' value='a devops guy' /> <option name='years' value='12' /> </options> </context> <defaultTab>nodes</defaultTab> <description></description> <executionEnabled>true</executionEnabled> <id>cc910bb3-9672-4038-b1e1-db4ec6d32e59</id> <loglevel>INFO</loglevel> <name>JobPython</name> <nodeFilterEditable>false</nodeFilterEditable> <plugins /> <scheduleEnabled>true</scheduleEnabled> <sequence keepgoing='false' strategy='node-first'> <command> <fileExtension>.py</fileExtension> <script><![CDATA[title = "@option.name@" years = @option.years@ print("I have been {} for {} years ".format(title, years))]]></script> <scriptargs /> <scriptinterpreter>/usr/bin/python3.8</scriptinterpreter> </command> </sequence> <uuid>cc910bb3-9672-4038-b1e1-db4ec6d32e59</uuid> </job> </joblist>
另外,您可以在Python参数上使用选项,只需确保在“arguments”文本框中传递这些参数,另一个示例:
<joblist> <job> <context> <options preserveOrder='true'> <option name='opt1' value='hello' /> <option name='opt2' value='world' /> <option name='opt3' value='devops' /> </options> </context> <defaultTab>nodes</defaultTab> <description></description> <executionEnabled>true</executionEnabled> <id>94045c34-0d8b-4bef-9248-08cf6f7b3a06</id> <loglevel>INFO</loglevel> <name>JobPythonWithArguments</name> <nodeFilterEditable>false</nodeFilterEditable> <plugins /> <scheduleEnabled>true</scheduleEnabled> <sequence keepgoing='false' strategy='node-first'> <command> <fileExtension>.py</fileExtension> <script><![CDATA[import sys print (sys.argv[1:]);]]></script> <scriptargs>${option.opt1} ${option.opt2} ${option.opt3}</scriptargs> <scriptinterpreter>/usr/bin/python3.8</scriptinterpreter> </command> </sequence> <uuid>94045c34-0d8b-4bef-9248-08cf6f7b3a06</uuid> </job> </joblist>
您可以用与Bash内联脚本相同的方式传递选项,只需确保在调用字符串文本框中使用python解释器路径,在“文件扩展名”文本框中使用“.py”(如果在创建或编辑作业时单击“高级”按钮,这两个选项都可以访问)
我举一个例子:
另外,您可以在Python参数上使用选项,只需确保在“arguments”文本框中传递这些参数,另一个示例:
相关问题 更多 >
编程相关推荐