为什么上传文件时出错
Why there is an error when uploading a file
{
'error': True,
'apiversion': 35,
'errorCode': 'api.error.job-upload.invalid',
'message': 'Job does not have file options’
}
您需要一个定义为 file type 的选项,而不是“文本”类型的选项。我留下一个工作定义示例(检查“选项”部分的“类型”属性):
<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 documentation, you need to "load" the file first and later run the job with the file id on your file option. I have used jq tool提取文件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"
}
现在作业可以print文件内容(这只是一个例子)。
另一种选择是使用 same process using RD CLI 工具,我认为最简单。
{
'error': True,
'apiversion': 35,
'errorCode': 'api.error.job-upload.invalid',
'message': 'Job does not have file options’
}
您需要一个定义为 file type 的选项,而不是“文本”类型的选项。我留下一个工作定义示例(检查“选项”部分的“类型”属性):
<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 documentation, you need to "load" the file first and later run the job with the file id on your file option. I have used jq tool提取文件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"
}
现在作业可以print文件内容(这只是一个例子)。
另一种选择是使用 same process using RD CLI 工具,我认为最简单。