为什么上传文件时出错

时间:2020-10-20 09:47:33

标签: rundeck

$stmt = $pdo->prepare("SELECT column1, column2, SUM(column3) FROM table GROUP BY column1, column2");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_ASSOC);

1 个答案:

答案 0 :(得分:0)

您需要一个定义为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之后,您需要先“加载”文件,然后在文件选项上使用文件ID运行作业。我已使用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工具来进行RD CLI