通过 Rundeck API 获取作业的最新执行

问题描述

我使用的是最新版本的 Rundeck (3.3.10),但无法通过 Rest API 获取作业的最新执行。

如果我调用 api/38/job//executions?max=1 它似乎不会恢复最新的执行,如果它仍在运行。理想情况下,我还希望能够在单个 API 调用中获得每个作业的最新执行开始时间、结束时间、用户和结果,但我已让自己为每个作业调用一次 API。似乎没有任何方法可以对您从 API 返回的执行进行排序 - 它们似乎首先按状态排序,因此正在运行的作业出现在列表的末尾。

有没有人知道解决这个问题的方法?谢谢。

解决方法

您可以使用以下方法获取该信息:executions?status=running&max=1 call

脚本示例:

#!/bin/sh

# protocol
protocol="http"

# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="38"
rdeck_token="YRVaZikt64Am85RyLo1nyq8U1Oe4Q8J7 "

# specific api call info
rdeck_job="03f28add-84f2-4013-b8f5-e48feaf5977c"

# api call
curl --location --request GET "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/job/$rdeck_job/executions?status=running&max=1" \
  --header "Accept: application/json" \
  --header "X-Rundeck-Auth-Token: $rdeck_token" \
  --header "Content-Type: application/json" 

输出:

{
  "paging": {
    "count": 1,"total": 1,"offset": 0,"max": 1
  },"executions": [
    {
      "id": 7,"href": "http://localhost:4440/api/38/execution/7","permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/7","status": "running","project": "ProjectEXAMPLE","executionType": "user","user": "admin","date-started": {
        "unixtime": 1617304896289,"date": "2021-04-01T19:21:36Z"
      },"job": {
        "id": "03f28add-84f2-4013-b8f5-e48feaf5977c","averageDuration": 13796,"name": "HelloWorld","group": "","description": "","href": "http://localhost:4440/api/38/job/03f28add-84f2-4013-b8f5-e48feaf5977c","permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/03f28add-84f2-4013-b8f5-e48feaf5977c"
      },"description": "sleep 20; echo \"hi\"","argstring": null,"serverUUID": "630be43c-e71f-4102-be96-d017dd22233e"
    }
  ]
}