rundeck - 为什么上传文件时出错
问题描述
{
'error': True,
'apiversion': 35,
'errorCode': 'api.error.job-upload.invalid',
'message': 'Job does not have file options’
}
解决方案
您需要将选项定义为文件类型而不是“文本”类型选项。我留下一个工作定义示例(检查“选项”部分的“类型”属性):
<joblist>
<job>
<context>
<options preserveOrder='true'>
<option name='file1' type='file' />
</options>
</context>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>36eac4c7-a421-43b8-9b71-2b07530912ec</id>
<loglevel>INFO</loglevel>
<name>Example</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<exec>cat ${file.file1}</exec>
</command>
</sequence>
<uuid>36eac4c7-a421-43b8-9b71-2b07530912ec</uuid>
</job>
</joblist>
按照 API文档,您需要先“加载”文件,然后使用文件选项上的文件 ID 运行作业。我已经使用jq 工具提取文件 id 以便稍后传递:
#!/bin/sh
# first, load the file and store the id on $fileid bash variable (the file is loaded on --data-binary section).
fileid=$(curl -s --location --request POST 'http://localhost:4440/api/36/job/36eac4c7-a421-43b8-9b71-2b07530912ec/input/file?optionName=file1&fileName=file.txt' \
--header 'Accept: application/json' \
--header 'X-Rundeck-Auth-Token: UkGOtMIUWjpNGcEsza9KoDZ94A9hRGKV' \
--header 'Content-Type: octet/stream' \
--data-binary "@/path/to/your/file" | jq -r '.options[]')
# now run the job passing the id saved at $fileid variable (check the argString section).
curl -s --location --request POST "http://localhost:4440/api/36/job/36eac4c7-a421-43b8-9b71-2b07530912ec/run" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: UkGOtMIUWjpNGcEsza9KoDZ94A9hRGKV" \
--header "Content-Type: application/json" \
--data "{ \"argString\":\"-file1 $fileid \" }" | jq
输出是(也使用 jq 来“美化”):
{
"id": 28,
"href": "http://localhost:4440/api/36/execution/28",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/28",
"status": "running",
"project": "ProjectEXAMPLE",
"executionType": "user",
"user": "admin",
"date-started": {
"unixtime": 1603198748079,
"date": "2020-10-20T12:59:08Z"
},
"job": {
"id": "36eac4c7-a421-43b8-9b71-2b07530912ec",
"averageDuration": 354,
"name": "Example",
"group": "",
"project": "ProjectEXAMPLE",
"description": "",
"options": {
"file1": "50bb60fc-7b4d-4322-b00f-7ee4f79f1502"
},
"href": "http://localhost:4440/api/36/job/36eac4c7-a421-43b8-9b71-2b07530912ec",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/36eac4c7-a421-43b8-9b71-2b07530912ec"
},
"description": "cat ${file.file1}",
"argstring": "-file1 50bb60fc-7b4d-4322-b00f-7ee4f79f1502",
"serverUUID": "d547091d-acf3-4437-bbba-2b093612a813"
}
现在作业可以打印文件内容(这只是一个示例)。
另一种选择是使用RD CLI工具执行相同的过程,我认为这是最简单的。
推荐阅读
- java - 我想启动一个方法或某个进程并保持 100 毫秒,然后在 android 中重新开始
- mongodb - 每次测试前 Mocha MongoDB 清理收集
- javascript - 使用 jQuery 自动完成 devbridge 更改 onSelect 事件的查询
- asp.net-mvc - 无法将相同的实体(具有不同的相关属性实体)插入另一个实体
- javascript - LinkedList - 创建函数,该函数接受一个值,创建一个节点,并将其添加到列表末尾
- ssl - 如何从现有证书中创建子证书?
- android - 在 XML 文件的预览呈现期间抛出异常 16,并且一个字符串抛出错误“在此处翻译但不在默认语言环境中”
- reactjs - CORS 错误 - 无法使用 React.js 从 JIRA 获取 Rest api
- excel - 带有 aftersave 子程序的无限循环
- node.js - 使用nodeJS和cheerio写入HTML文件时获取特殊字符而不是单引号